[ofbiz-framework] branch trunk updated: Improved: Defects reported by code analysis tool. (OFBIZ-10571)

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

[ofbiz-framework] branch trunk updated: Improved: Defects reported by code analysis tool. (OFBIZ-10571)

surajk
This is an automated email from the ASF dual-hosted git repository.

surajk pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git


The following commit(s) were added to refs/heads/trunk by this push:
     new cc52b98  Improved: Defects reported by code analysis tool. (OFBIZ-10571)
     new 2c1fe93  Merge branch 'trunk' of https://gitbox.apache.org/repos/asf/ofbiz-framework into trunk
cc52b98 is described below

commit cc52b981510caeed57ae4cb0d70f13c0017d4445
Author: Suraj Khurana <[hidden email]>
AuthorDate: Wed Feb 26 16:06:55 2020 +0530

    Improved: Defects reported by code analysis tool.
    (OFBIZ-10571)
   
    Following refactoring done -
    -- Refactored code to fall in line with some java standards.
    -- Based on FindBugs suggestion, refactored some classes to have static nested classes instead of inner class.
   
    Thanks Girish Vasmatkar for reporting the issue and providing the patch.
---
 .../ofbiz/minilang/method/callops/CallService.java   | 20 ++++++++++----------
 .../ofbiz/minilang/method/entityops/EntityCount.java |  4 ++--
 .../ofbiz/minilang/method/otherops/Calculate.java    |  2 +-
 .../apache/ofbiz/minilang/method/otherops/Log.java   |  6 +++---
 4 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/framework/minilang/src/main/java/org/apache/ofbiz/minilang/method/callops/CallService.java b/framework/minilang/src/main/java/org/apache/ofbiz/minilang/method/callops/CallService.java
index 56a40ca..b600daa 100644
--- a/framework/minilang/src/main/java/org/apache/ofbiz/minilang/method/callops/CallService.java
+++ b/framework/minilang/src/main/java/org/apache/ofbiz/minilang/method/callops/CallService.java
@@ -53,8 +53,8 @@ import org.w3c.dom.Element;
  */
 public final class CallService extends MethodOperation {
 
-    public static final String module = CallService.class.getName();
-    public static final String resource = "MiniLangErrorUiLabels";
+    private static final String MODULE = CallService.class.getName();
+    public static final String RESOURCE = "MiniLangErrorUiLabels";
 
     private final boolean breakOnError;
     private final FlexibleMessage defaultMessage;
@@ -220,7 +220,7 @@ public final class CallService extends MethodOperation {
                 outputTraceMessage(methodContext, "Service engine threw an exception: " + e.getMessage());
             }
             String errMsg = "ERROR: Could not complete the " + simpleMethod.getShortDescription() + " process [problem invoking the [" + serviceName + "] service with the map named [" + inMapFma + "] containing [" + inMap + "]: " + e.getMessage() + "]";
-            Debug.logError(e, errMsg, module);
+            Debug.logError(e, errMsg, MODULE);
             if (breakOnError) {
                 if (methodContext.getMethodType() == MethodContext.EVENT) {
                     methodContext.putEnv(simpleMethod.getEventErrorMessageName(), errMsg);
@@ -300,18 +300,18 @@ public final class CallService extends MethodOperation {
             if (methodContext.getMethodType() == MethodContext.EVENT) {
                 if (UtilValidate.isNotEmpty(errorMessage)) {
                     if (Debug.verboseOn()) {
-                        errorMessage += UtilProperties.getMessage(resource, "simpleMethod.error_show_service_name", UtilMisc.toMap("serviceName", serviceName, "methodName", simpleMethod.getMethodName()), locale);
+                        errorMessage += UtilProperties.getMessage(RESOURCE, "simpleMethod.error_show_service_name", UtilMisc.toMap("serviceName", serviceName, "methodName", simpleMethod.getMethodName()), locale);
                     }
                     methodContext.putEnv(simpleMethod.getEventErrorMessageName(), errorMessage);
                 } else {
                     if (Debug.verboseOn()) {
-                        errorMessageList.add(UtilProperties.getMessage(resource, "simpleMethod.error_show_service_name", UtilMisc.toMap("serviceName", serviceName, "methodName", simpleMethod.getMethodName()), locale));
+                        errorMessageList.add(UtilProperties.getMessage(RESOURCE, "simpleMethod.error_show_service_name", UtilMisc.toMap("serviceName", serviceName, "methodName", simpleMethod.getMethodName()), locale));
                     }
                     methodContext.putEnv(simpleMethod.getEventErrorMessageListName(), errorMessageList);
                 }
             } else {
                 ServiceUtil.addErrors(UtilMisc.<String, String> getListFromMap(methodContext.getEnvMap(), this.simpleMethod.getServiceErrorMessageListName()), UtilMisc.<String, String, Object> getMapFromMap(methodContext.getEnvMap(), this.simpleMethod.getServiceErrorMessageMapName()), result);
-                Debug.logError(new Exception(errorMessage), module);
+                Debug.logError(new Exception(errorMessage), MODULE);
             }
         }
         String successMessage = ServiceUtil.makeSuccessMessage(result, messagePrefixStr, messageSuffixStr, successPrefixStr, successSuffixStr);
@@ -395,7 +395,7 @@ public final class CallService extends MethodOperation {
         }
     }
 
-    private final class ResultToField {
+    private static final class ResultToField {
         private final FlexibleMapAccessor<Object> fieldFma;
         private final FlexibleMapAccessor<Object> resultFma;
 
@@ -414,7 +414,7 @@ public final class CallService extends MethodOperation {
         }
     }
 
-    private final class ResultToRequest {
+    private static final class ResultToRequest {
         private final FlexibleMapAccessor<Object> resultFma;
         private final FlexibleServletAccessor<Object> requestFsa;
 
@@ -428,7 +428,7 @@ public final class CallService extends MethodOperation {
         }
     }
 
-    private final class ResultToResult {
+    private static final class ResultToResult {
         private final FlexibleMapAccessor<Object> resultFma;
         private final FlexibleMapAccessor<Object> serviceResultFma;
 
@@ -447,7 +447,7 @@ public final class CallService extends MethodOperation {
         }
     }
 
-    private final class ResultToSession {
+    private static final class ResultToSession {
         private final FlexibleMapAccessor<Object> resultFma;
         private final FlexibleServletAccessor<Object> requestFsa;
 
diff --git a/framework/minilang/src/main/java/org/apache/ofbiz/minilang/method/entityops/EntityCount.java b/framework/minilang/src/main/java/org/apache/ofbiz/minilang/method/entityops/EntityCount.java
index 1b87c6b..461696e 100644
--- a/framework/minilang/src/main/java/org/apache/ofbiz/minilang/method/entityops/EntityCount.java
+++ b/framework/minilang/src/main/java/org/apache/ofbiz/minilang/method/entityops/EntityCount.java
@@ -45,7 +45,7 @@ import org.w3c.dom.Element;
  */
 public final class EntityCount extends EntityOperation {
 
-    public static final String module = EntityCount.class.getName();
+    private static final String MODULE = EntityCount.class.getName();
 
     private final FlexibleMapAccessor<Long> countFma;
     private final FlexibleStringExpander entityNameFse;
@@ -108,7 +108,7 @@ public final class EntityCount extends EntityOperation {
             this.countFma.put(methodContext.getEnvMap(), count);
         } catch (GeneralException e) {
             String errMsg = "Exception thrown while performing entity count: " + e.getMessage();
-            Debug.logWarning(e, errMsg, module);
+            Debug.logWarning(e, errMsg, MODULE);
             simpleMethod.addErrorMessage(methodContext, errMsg);
             return false;
         }
diff --git a/framework/minilang/src/main/java/org/apache/ofbiz/minilang/method/otherops/Calculate.java b/framework/minilang/src/main/java/org/apache/ofbiz/minilang/method/otherops/Calculate.java
index 9d4188d..c20e6c6 100644
--- a/framework/minilang/src/main/java/org/apache/ofbiz/minilang/method/otherops/Calculate.java
+++ b/framework/minilang/src/main/java/org/apache/ofbiz/minilang/method/otherops/Calculate.java
@@ -129,7 +129,7 @@ public final class Calculate extends MethodOperation {
         String decimalScaleString = decimalScaleFse.expandString(methodContext.getEnvMap());
         int decimalScale = 2;
         if (!decimalScaleString.isEmpty()) {
-            decimalScale = Integer.valueOf(decimalScaleString);
+            decimalScale = Integer.parseInt(decimalScaleString);
         }
         BigDecimal resultValue = BigDecimal.ZERO.setScale(decimalScale, roundingMode);
         for (Calculate.SubCalc calcop : calcops) {
diff --git a/framework/minilang/src/main/java/org/apache/ofbiz/minilang/method/otherops/Log.java b/framework/minilang/src/main/java/org/apache/ofbiz/minilang/method/otherops/Log.java
index 716aa3e..9d9f798 100644
--- a/framework/minilang/src/main/java/org/apache/ofbiz/minilang/method/otherops/Log.java
+++ b/framework/minilang/src/main/java/org/apache/ofbiz/minilang/method/otherops/Log.java
@@ -35,8 +35,8 @@ import org.w3c.dom.Element;
  */
 public final class Log extends MethodOperation {
 
-    public static final String module = Log.class.getName();
-    public static final String[] LEVEL_ARRAY = {"always", "verbose", "timing", "info", "important", "warning", "error", "fatal", "notify"};
+    private static final String MODULE = Log.class.getName();
+    protected static final String[] LEVEL_ARRAY = {"always", "verbose", "timing", "info", "important", "warning", "error", "fatal", "notify"};
 
     private final int level;
     private final FlexibleStringExpander messageFse;
@@ -81,7 +81,7 @@ public final class Log extends MethodOperation {
             buf.append(getLineNumber());
             buf.append("] ");
             buf.append(message);
-            Debug.log(this.level, null, buf.toString(), module);
+            Debug.log(this.level, null, buf.toString(), MODULE);
         }
         return true;
     }