svn commit: r1817571 - in /ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget: WidgetFactory.java WidgetWorker.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1817571 - in /ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget: WidgetFactory.java WidgetWorker.java

mbrohl
Author: mbrohl
Date: Fri Dec  8 21:19:32 2017
New Revision: 1817571

URL: http://svn.apache.org/viewvc?rev=1817571&view=rev
Log:
Improved: Fixing defects reported by FindBugs, package
org.apache.ofbiz.widget.
(OFBIZ-9724)

Thanks Dennis Balkir for reporting and providing the patch.

Modified:
    ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/WidgetFactory.java
    ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/WidgetWorker.java

Modified: ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/WidgetFactory.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/WidgetFactory.java?rev=1817571&r1=1817570&r2=1817571&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/WidgetFactory.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/WidgetFactory.java Fri Dec  8 21:19:32 2017
@@ -42,7 +42,7 @@ import org.w3c.dom.Element;
 public class WidgetFactory {
 
     public static final String module = WidgetFactory.class.getName();
-    protected static final Map<String, Constructor<? extends ModelScreenWidget>> screenWidgets = new ConcurrentHashMap<String, Constructor<? extends ModelScreenWidget>>();
+    protected static final Map<String, Constructor<? extends ModelScreenWidget>> screenWidgets = new ConcurrentHashMap<>();
 
     static {
         loadStandardWidgets();
@@ -99,7 +99,9 @@ public class WidgetFactory {
                             Class<? extends ModelScreenWidget> widgetClass = UtilGenerics.cast(clz);
                             registerScreenWidget(fieldObject.toString(), widgetClass);
                         }
-                    } catch (Exception e) {}
+                    } catch (Exception e) {
+                        Debug.logError(e, module);
+                    }
                 }
             } catch (Exception e) {
                 Debug.logError(e, module);

Modified: ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/WidgetWorker.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/WidgetWorker.java?rev=1817571&r1=1817570&r2=1817571&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/WidgetWorker.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/WidgetWorker.java Fri Dec  8 21:19:32 2017
@@ -84,8 +84,6 @@ public final class WidgetWorker {
             }
         } else if ("content".equals(targetType)) {
             appendContentUrl(localWriter, localRequestName, request);
-        } else if ("plain".equals(targetType)) {
-            localWriter.append(localRequestName);
         } else {
             localWriter.append(localRequestName);
         }
@@ -148,9 +146,12 @@ public final class WidgetWorker {
     public static void makeHyperlinkByType(Appendable writer, String linkType, String linkStyle, String targetType, String target,
             Map<String, String> parameterMap, String description, String targetWindow, String confirmation, ModelFormField modelFormField,
             HttpServletRequest request, HttpServletResponse response, Map<String, Object> context) throws IOException {
+        if (modelFormField == null) {
+            throw new IllegalArgumentException("modelFormField in WidgetWorker.makeHyperlinkByType has turned out to be null");
+        }
         String realLinkType = WidgetWorker.determineAutoLinkType(linkType, target, targetType, request);
         if ("hidden-form".equals(realLinkType)) {
-            if (modelFormField != null && "multi".equals(modelFormField.getModelForm().getType())) {
+            if ("multi".equals(modelFormField.getModelForm().getType())) {
                 WidgetWorker.makeHiddenFormLinkAnchor(writer, linkStyle, description, confirmation, modelFormField, request, response, context);
 
                 // this is a bit trickier, since we can't do a nested form we'll have to put the link to submit the form in place, but put the actual form def elsewhere, ie after the big form is closed
@@ -158,7 +159,6 @@ public final class WidgetWorker {
                 Appendable postMultiFormWriter = wholeFormContext != null ? (Appendable) wholeFormContext.get("postMultiFormWriter") : null;
                 if (postMultiFormWriter == null) {
                     postMultiFormWriter = new StringWriter();
-                    wholeFormContext.put("postMultiFormWriter", postMultiFormWriter);
                 }
                 WidgetWorker.makeHiddenFormLinkForm(postMultiFormWriter, target, targetType, targetWindow, parameterMap, modelFormField, request, response, context);
             } else {
@@ -309,9 +309,8 @@ public final class WidgetWorker {
         }
         if (itemIndex != null) {
             return formName + modelForm.getItemIndexSeparator() + itemIndex.intValue() + iterateId + formUniqueId + modelForm.getItemIndexSeparator() + modelFormField.getName();
-        } else {
-            return formName + modelForm.getItemIndexSeparator() + modelFormField.getName();
         }
+        return formName + modelForm.getItemIndexSeparator() + modelFormField.getName();
     }
     public static String determineAutoLinkType(String linkType, String target, String targetType, HttpServletRequest request) {
         if ("auto".equals(linkType)) {
@@ -327,15 +326,11 @@ public final class WidgetWorker {
                 }
                 if (requestMap != null && requestMap.event != null) {
                     return "hidden-form";
-                } else {
-                    return "anchor";
                 }
-            } else {
-                return "anchor";
             }
-        } else {
-            return linkType;
+            return "anchor";
         }
+        return linkType;
     }
 
     /** Returns the script location based on a script combined name:
@@ -345,7 +340,7 @@ public final class WidgetWorker {
      * @return The script location
      */
     public static String getScriptLocation(String combinedName) {
-        int pos = combinedName.lastIndexOf("#");
+        int pos = combinedName.lastIndexOf('#');
         if (pos == -1) {
             return combinedName;
         }
@@ -360,7 +355,7 @@ public final class WidgetWorker {
      * @return The method name or <code>null</code>
      */
     public static String getScriptMethodName(String combinedName) {
-        int pos = combinedName.lastIndexOf("#");
+        int pos = combinedName.lastIndexOf('#');
         if (pos == -1) {
             return null;
         }