Author: deepak
Date: Tue May 16 17:20:24 2017
New Revision: 1795342

URL: http://svn.apache.org/viewvc?rev=1795342&view=rev
Log:
Improved: Inconsistent String Comparisons, Applied framework groovy patch from 
jira issue. (OFBIZ-9254)

I found an inconsistency in the code for string comparison 
statusId.equals("PRUN_COMPLETED") whereas it should be written as 
"PRUN_COMPLETED".equals(statusId) cause the former can throw 
NullPointerException if the variable found to be NULL.

Thanks Devanshu Vyas for your contribution.

Modified:
    
ofbiz/ofbiz-framework/trunk/framework/common/groovyScripts/SetLocaleFromBrowser.groovy
    
ofbiz/ofbiz-framework/trunk/framework/webtools/groovyScripts/entity/ViewGeneric.groovy
    
ofbiz/ofbiz-framework/trunk/framework/webtools/groovyScripts/service/AvailableServices.groovy

Modified: 
ofbiz/ofbiz-framework/trunk/framework/common/groovyScripts/SetLocaleFromBrowser.groovy
URL: 
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/common/groovyScripts/SetLocaleFromBrowser.groovy?rev=1795342&r1=1795341&r2=1795342&view=diff
==============================================================================
--- 
ofbiz/ofbiz-framework/trunk/framework/common/groovyScripts/SetLocaleFromBrowser.groovy
 (original)
+++ 
ofbiz/ofbiz-framework/trunk/framework/common/groovyScripts/SetLocaleFromBrowser.groovy
 Tue May 16 17:20:24 2017
@@ -25,7 +25,7 @@ public Map setLocaleFromBrowser() {
     Map results = ServiceUtil.returnSuccess()
     userLogin = 
EntityQuery.use(delegator).from("UserLogin").where("userLoginId", 
parameters.userLogin.userLoginId).queryFirst();
     if (userLogin) {
-        if (!userLogin.lastTimeZone || userLogin.lastTimeZone.equals("null")) {
+        if (!userLogin.lastTimeZone || "null".equals(userLogin.lastTimeZone)) {
             userLogin.lastTimeZone = parameters.localeName
             userLogin.store()
         }

Modified: 
ofbiz/ofbiz-framework/trunk/framework/webtools/groovyScripts/entity/ViewGeneric.groovy
URL: 
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/webtools/groovyScripts/entity/ViewGeneric.groovy?rev=1795342&r1=1795341&r2=1795342&view=diff
==============================================================================
--- 
ofbiz/ofbiz-framework/trunk/framework/webtools/groovyScripts/entity/ViewGeneric.groovy
 (original)
+++ 
ofbiz/ofbiz-framework/trunk/framework/webtools/groovyScripts/entity/ViewGeneric.groovy
 Tue May 16 17:20:24 2017
@@ -99,13 +99,13 @@ if (value != null) {
         ModelFieldType type = delegator.getEntityFieldType(entity, 
field.getType())
 
         String fieldValue = ""
-        if (type.getJavaType().equals("Timestamp") || 
type.getJavaType().equals("java.sql.Timestamp")) {
+        if ("Timestamp".equals(type.getJavaType()) || 
"java.sql.Timestamp".equals(type.getJavaType())) {
             Timestamp dtVal = value.getTimestamp(field.getName())
             fieldValue = (dtVal == null) ? "" : dtVal.toString()
-        } else if (type.getJavaType().equals("Date") || 
type.getJavaType().equals("java.sql.Date")) {
+        } else if ("Date".equals(type.getJavaType()) || 
"java.sql.Date".equals(type.getJavaType())) {
             Date dateVal = value.getDate(field.getName())
             fieldValue = (dateVal == null) ? "" : dateVal.toString()
-        } else if (type.getJavaType().equals("Time") || 
type.getJavaType().equals("java.sql.Time")) {
+        } else if ("Time".equals(type.getJavaType()) || 
"java.sql.Time".equals(type.getJavaType())) {
             Time timeVal = value.getTime(field.getName())
             fieldValue = (timeVal == null) ? "" : timeVal.toString()
         } else if (type.getJavaType().indexOf("Integer") >= 0) {
@@ -138,7 +138,7 @@ context.put("pkNotFound", pkNotFound)
 
 String lastUpdateMode = parameters.get("UPDATE_MODE")
 if ((session.getAttribute("_ERROR_MESSAGE_") != null || 
request.getAttribute("_ERROR_MESSAGE_") != null) &&
-    lastUpdateMode != null && !lastUpdateMode.equals("DELETE")) {
+    lastUpdateMode != null && !"DELETE".equals(lastUpdateMode)) {
     //if we are updating and there is an error, do not use the entity data for 
the fields, use parameters to get the old value
     useValue = false
 }
@@ -155,7 +155,7 @@ while (pkIterator.hasNext()) {
     String fieldValue = ""
     String fieldType = ""
     String stringLength = ""
-    if (type.getJavaType().equals("Timestamp") || 
type.getJavaType().equals("java.sql.Timestamp")) {
+    if ("Timestamp".equals(type.getJavaType()) || 
"java.sql.Timestamp".equals(type.getJavaType())) {
         String dateTimeString = null
         if (findByPK != null && useValue) {
             Timestamp dtVal = findByPK.getTimestamp(field.getName())
@@ -167,7 +167,7 @@ while (pkIterator.hasNext()) {
         }
         fieldValue = UtilFormatOut.checkNull(dateTimeString)
         fieldType = "DateTime"
-    } else if (type.getJavaType().equals("Date") || 
type.getJavaType().equals("java.sql.Date")) {
+    } else if ("Date".equals(type.getJavaType()) || 
"java.sql.Date".equals(type.getJavaType())) {
         String dateString = null
         if (findByPK != null && useValue) {
             Date dateVal = findByPK.getDate(field.getName())
@@ -177,7 +177,7 @@ while (pkIterator.hasNext()) {
         }
         fieldValue = UtilFormatOut.checkNull(dateString)
         fieldType = "Date"
-    } else if (type.getJavaType().equals("Time") || 
type.getJavaType().equals("java.sql.Time")) {
+    } else if ("Time".equals(type.getJavaType()) || 
"java.sql.Time".equals(type.getJavaType())) {
         String timeString = null
         if (findByPK != null && useValue) {
             Time timeVal = findByPK.getTime(field.getName())
@@ -232,7 +232,7 @@ while (noPkIterator.hasNext()) {
     String fieldValue = ""
     String fieldType = ""
     String stringLength = ""
-    if (type.getJavaType().equals("Timestamp") || 
type.getJavaType().equals("java.sql.Timestamp")) {
+    if ("Timestamp".equals(type.getJavaType()) || 
"java.sql.Timestamp".equals(type.getJavaType())) {
         String dateTimeString = null
         if (value != null && useValue) {
             Timestamp dtVal = value.getTimestamp(field.getName())
@@ -244,7 +244,7 @@ while (noPkIterator.hasNext()) {
         }
         fieldValue = UtilFormatOut.checkNull(dateTimeString)
         fieldType = "DateTime"
-    } else if (type.getJavaType().equals("Date") || 
type.getJavaType().equals("java.sql.Date")) {
+    } else if ("Date".equals(type.getJavaType()) || 
"java.sql.Date".equals(type.getJavaType())) {
         String dateString = null
         if (value != null && useValue) {
             Date dateVal = value.getDate(field.getName())
@@ -254,7 +254,7 @@ while (noPkIterator.hasNext()) {
         }
         fieldValue = UtilFormatOut.checkNull(dateString)
         fieldType = "Date"
-    } else if (type.getJavaType().equals("Time") || 
type.getJavaType().equals("java.sql.Time")) {
+    } else if ("Time".equals(type.getJavaType()) || 
"java.sql.Time".equals(type.getJavaType())) {
         String timeString = null
         if (value != null && useValue) {
             Time timeVal = value.getTime(field.getName())
@@ -338,21 +338,21 @@ for (int relIndex = 0; relIndex < entity
 
                     String fieldValue = ""
                     String fieldType = ""
-                    if (type.getJavaType().equals("Timestamp") || 
type.getJavaType().equals("java.sql.Timestamp")) {
+                    if ("Timestamp".equals(type.getJavaType()) || 
"java.sql.Timestamp".equals(type.getJavaType())) {
                         Timestamp dtVal = null
                         if (valueRelated != null) {
                             dtVal = valueRelated.getTimestamp(field.getName())
                         }
                         fieldValue = (dtVal == null) ? "" : dtVal.toString()
                         fieldType = "DateTime"
-                    } else if (type.getJavaType().equals("Date") || 
type.getJavaType().equals("java.sql.Date")) {
+                    } else if ("Date".equals(type.getJavaType()) || 
"java.sql.Date".equals(type.getJavaType())) {
                         Date dateVal = null
                         if (valueRelated != null) {
                             dateVal = valueRelated.getDate(field.getName())
                         }
                         fieldValue = (dateVal == null) ? "" : 
dateVal.toString()
                         fieldType = "Date"
-                    } else if (type.getJavaType().equals("Time") || 
type.getJavaType().equals("java.sql.Time")) {
+                    } else if ("Time".equals(type.getJavaType()) || 
"java.sql.Time".equals(type.getJavaType())) {
                         Time timeVal = null
                         if (valueRelated != null) {
                             timeVal = valueRelated.getTime(field.getName())

Modified: 
ofbiz/ofbiz-framework/trunk/framework/webtools/groovyScripts/service/AvailableServices.groovy
URL: 
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/webtools/groovyScripts/service/AvailableServices.groovy?rev=1795342&r1=1795341&r2=1795342&view=diff
==============================================================================
--- 
ofbiz/ofbiz-framework/trunk/framework/webtools/groovyScripts/service/AvailableServices.groovy
 (original)
+++ 
ofbiz/ofbiz-framework/trunk/framework/webtools/groovyScripts/service/AvailableServices.groovy
 Tue May 16 17:20:24 2017
@@ -381,7 +381,7 @@ if (selectedService) {
         curServiceMap.export = export
         curServiceMap.exportBool = exportBool
 
-        if (permissionGroups && !permissionGroups.equals("NA")) {
+        if (permissionGroups && !"NA".equals(permissionGroups)) {
             permList = new ArrayList(permissionGroups.size())
             permissionGroups.each { curPerm ->  //This is a ModelPermGroup
                 curPerm.permissions.each { curPermObj ->
@@ -475,7 +475,7 @@ if (selectedService) {
 
     showWsdl = parameters.show_wsdl
 
-    if (showWsdl?.equals("true")) {
+    if ("true".equals(showWsdl)) {
         try {
             wsdl = 
curServiceModel.toWSDL("http://${request.getServerName()}:${EntityUtilProperties.getPropertyValue("url",
 "port.http", "80", delegator)}${parameters._CONTROL_PATH_}/SOAPService")
             curServiceMap.wsdl = UtilXml.writeXmlDocument(wsdl)
@@ -517,34 +517,34 @@ if (!selectedService) {
             constraintName = consArr[0]
             constraintVal = consArr[1]
 
-            if (constraintName.equals("engine_name")) {
+            if ("engine_name".equals(constraintName)) {
                 canIncludeService = 
curServiceModel.engineName.equals(constraintVal)
-                if (constraintVal.equals("NA")) {
+                if ("NA".equals(constraintVal)) {
                     canIncludeService = curServiceModel.engineName ? false : 
true
                 }
             }
 
-            if (canIncludeService && 
constraintName.equals("default_entity_name")) {
+            if (canIncludeService && 
"default_entity_name".equals(constraintName)) {
                 canIncludeService = 
curServiceModel.defaultEntityName.equals(constraintVal)
-                if (constraintVal.equals("NA")) {
+                if ("NA".equals(constraintVal)) {
                     canIncludeService = curServiceModel.defaultEntityName ? 
false : true
                 }
             }
 
-            if (canIncludeService && constraintName.equals("location")) {
+            if (canIncludeService && "location".equals(constraintName)) {
                 canIncludeService = 
curServiceModel.location.equals(constraintVal)
-                if (constraintVal.equals("NA")) {
+                if ("NA".equals(constraintVal)) {
                     canIncludeService = curServiceModel.location ? false : true
                 }
             }
 
-            if (canIncludeService && 
constraintName.equals("definitionLocation")) {
+            if (canIncludeService && 
"definitionLocation".equals(constraintName)) {
                 canIncludeService = 
curServiceModel.definitionLocation.equals(constraintVal)
             }
 
-            if (canIncludeService && constraintName.equals("alpha")) {
+            if (canIncludeService && "alpha".equals(constraintName)) {
                 canIncludeService = (serviceName[0]).equals(constraintVal)
-                if (constraintVal.equals("NA")) {
+                if ("NA".equals(constraintVal)) {
                     canIncludeService = true
                 }
             }


Reply via email to