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

jleroux 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 8b9fc99  Improved: Fix some bugs Spotbugs reports (OFBIZ-12386)
8b9fc99 is described below

commit 8b9fc99d7df10246c95d2280376441d085e72f3f
Author: Jacques Le Roux <[email protected]>
AuthorDate: Fri Dec 10 15:51:17 2021 +0100

    Improved: Fix some bugs Spotbugs reports (OFBIZ-12386)
    
    In ProductWorker::getProductFeaturesApplIncludeMarketingPackage fixes a 
possible
    null dereferencement (tested too late)
    
    In FileUtil::unZip uses a try-w-resource w/ ZipFile to close it. I crossed 
an
    issue with automated OOTB formatting (clean-up on save in Eclipse). Fixed 
with
    my external default editor (could not find where to change that in
    OFBizJavaFormatter.xml
    
    In ServiceArtifactInfo::calledServiceEcaSet fixes a possible null 
dereferencement
    (tested too late), also minor formatting
    
    In MacroScreenRenderer::renderScreenletSubWidget fixes a possible null
    dereferencement (tested too late)
    
    in FileUtil
---
 .../ofbiz/product/product/ProductWorker.java       |  2 +-
 .../java/org/apache/ofbiz/base/util/FileUtil.java  | 13 ++-
 .../webtools/artifactinfo/ServiceArtifactInfo.java | 93 +++++++++++-----------
 .../widget/renderer/macro/MacroScreenRenderer.java |  4 +-
 4 files changed, 56 insertions(+), 56 deletions(-)

diff --git 
a/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductWorker.java
 
b/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductWorker.java
index b10da4a..36d3a44 100644
--- 
a/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductWorker.java
+++ 
b/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductWorker.java
@@ -418,8 +418,8 @@ public final class ProductWorker {
     }
 
     public static List<GenericValue> 
getProductFeaturesApplIncludeMarketingPackage(GenericValue product) {
-        Delegator delegator = product.getDelegator();
         if (product != null) {
+            Delegator delegator = product.getDelegator();
             try {
                 List<String> productIds = 
UtilMisc.toList(product.getString("productId"));
 
diff --git 
a/framework/base/src/main/java/org/apache/ofbiz/base/util/FileUtil.java 
b/framework/base/src/main/java/org/apache/ofbiz/base/util/FileUtil.java
index 068f365..a2b871e 100644
--- a/framework/base/src/main/java/org/apache/ofbiz/base/util/FileUtil.java
+++ b/framework/base/src/main/java/org/apache/ofbiz/base/util/FileUtil.java
@@ -50,7 +50,6 @@ import org.apache.commons.io.FileUtils;
 import org.apache.ofbiz.base.location.ComponentLocationResolver;
 
 import net.lingala.zip4j.ZipFile;
-import net.lingala.zip4j.exception.ZipException;
 
 /**
  * File Utilities
@@ -525,7 +524,7 @@ public final class FileUtil {
     }
 
     /**
-     * Unzip file structure of the given zipFile to specified outputFolder The 
Zip slip vulnerabilty is handled since version 1.3.3 of
+     * Unzip file structure of the given zipFile to specified outputFolder The 
Zip slip vulnerability is handled since version 1.3.3 of
      * net.lingala.zip4j.ZipFile; unzipFileToFolder is not as reliable and 
does not handle passwords
      * @param source
      * @param destination
@@ -533,17 +532,17 @@ public final class FileUtil {
      * @return true if OK
      */
     public static boolean unZip(String source, String destination, String 
password) {
-        try {
+        try (ZipFile zipSource = new ZipFile(source);
+                 ZipFile zipSourcePwd = new ZipFile(source, 
password.toCharArray())) {
             if (password.isEmpty()) {
-                new ZipFile(source).extractAll(destination);
+                zipSource.extractAll(destination);
             } else {
-                new ZipFile(source, 
password.toCharArray()).extractAll(destination);
+                zipSourcePwd.extractAll(destination);
             }
-        } catch (ZipException e) {
+        } catch (IOException e) {
             Debug.logError("Error extracting [" + source + "] file to dir 
destination: " + destination, e.toString(), MODULE);
             return false;
         }
         return true;
     }
-
 }
diff --git 
a/framework/webtools/src/main/java/org/apache/ofbiz/webtools/artifactinfo/ServiceArtifactInfo.java
 
b/framework/webtools/src/main/java/org/apache/ofbiz/webtools/artifactinfo/ServiceArtifactInfo.java
index 4cf85a6..effde04 100644
--- 
a/framework/webtools/src/main/java/org/apache/ofbiz/webtools/artifactinfo/ServiceArtifactInfo.java
+++ 
b/framework/webtools/src/main/java/org/apache/ofbiz/webtools/artifactinfo/ServiceArtifactInfo.java
@@ -463,56 +463,59 @@ public class ServiceArtifactInfo extends ArtifactInfoBase 
{
 
         // all SECAs and corresponding services triggered by this service
         Set<ServiceEcaArtifactInfo> calledServiceEcaSet = 
this.getServiceEcaRulesTriggeredByService();
-        for (ServiceEcaArtifactInfo calledServiceEca: calledServiceEcaSet) {
-            calledServiceEca.setDisplayPrefix("Triggered_");
-
-            Integer displaySuffix = 
displaySuffixNumByEcaName.get(calledServiceEca.getDisplayPrefixedName());
-            if (displaySuffix == null) {
-                displaySuffix = 1;
-            } else {
-                displaySuffix++;
-            }
-            
displaySuffixNumByEcaName.put(calledServiceEca.getDisplayPrefixedName(), 
displaySuffix);
-            calledServiceEca.setDisplaySuffixNum(displaySuffix);
-
-            
allDiagramEntitiesWithPrefixes.add(calledServiceEca.getDisplayPrefixedName());
-            allServiceEcaList.add(calledServiceEca);
-        }
+        if (calledServiceEcaSet != null) {
+            for (ServiceEcaArtifactInfo calledServiceEca : 
calledServiceEcaSet) {
+                calledServiceEca.setDisplayPrefix("Triggered_");
 
-        // write index.eomodeld file
-        Map<String, Object> indexEoModelMap = new HashMap<>();
-        indexEoModelMap.put("EOModelVersion", "\"2.1\"");
-        List<Map<String, Object>> entitiesMapList = new LinkedList<>();
-        indexEoModelMap.put("entities", entitiesMapList);
-        for (String entityName: allDiagramEntitiesWithPrefixes) {
-            Map<String, Object> entitiesMap = new HashMap<>();
-            entitiesMapList.add(entitiesMap);
-            entitiesMap.put("className", "EOGenericRecord");
-            entitiesMap.put("name", entityName);
-        }
-        UtilPlist.writePlistFile(indexEoModelMap, eomodeldFullPath, 
"index.eomodeld", true);
+                Integer displaySuffix = 
displaySuffixNumByEcaName.get(calledServiceEca.getDisplayPrefixedName());
+                if (displaySuffix == null) {
+                    displaySuffix = 1;
+                } else {
+                    displaySuffix++;
+                }
+                
displaySuffixNumByEcaName.put(calledServiceEca.getDisplayPrefixedName(), 
displaySuffix);
+                calledServiceEca.setDisplaySuffixNum(displaySuffix);
 
-        // write this service description file
-        Map<String, Object> thisServiceEoModelMap = 
createEoModelMap(callingServiceSet, calledServiceSet, callingServiceEcaSet, 
calledServiceEcaSet,
-                useMoreDetailedNames);
-        UtilPlist.writePlistFile(thisServiceEoModelMap, eomodeldFullPath, 
this.modelService.getName() + ".plist", true);
+                
allDiagramEntitiesWithPrefixes.add(calledServiceEca.getDisplayPrefixedName());
+                allServiceEcaList.add(calledServiceEca);
+            }
 
-        // write service description files
-        if (callingServiceSet != null) {
-            for (ServiceArtifactInfo callingService: callingServiceSet) {
-                Map<String, Object> serviceEoModelMap = 
callingService.createEoModelMap(null, UtilMisc.toSet(this), null, null, 
useMoreDetailedNames);
-                UtilPlist.writePlistFile(serviceEoModelMap, eomodeldFullPath, 
callingService.getDisplayPrefixedName() + ".plist", true);
+            // write index.eomodeld file
+            Map<String, Object> indexEoModelMap = new HashMap<>();
+            indexEoModelMap.put("EOModelVersion", "\"2.1\"");
+            List<Map<String, Object>> entitiesMapList = new LinkedList<>();
+            indexEoModelMap.put("entities", entitiesMapList);
+            for (String entityName : allDiagramEntitiesWithPrefixes) {
+                Map<String, Object> entitiesMap = new HashMap<>();
+                entitiesMapList.add(entitiesMap);
+                entitiesMap.put("className", "EOGenericRecord");
+                entitiesMap.put("name", entityName);
             }
-        }
-        if (calledServiceSet != null) {
-            for (ServiceArtifactInfo calledService: calledServiceSet) {
-                Map<String, Object> serviceEoModelMap = 
calledService.createEoModelMap(UtilMisc.toSet(this), null, null, null, 
useMoreDetailedNames);
-                UtilPlist.writePlistFile(serviceEoModelMap, eomodeldFullPath, 
calledService.getDisplayPrefixedName() + ".plist", true);
+            UtilPlist.writePlistFile(indexEoModelMap, eomodeldFullPath, 
"index.eomodeld", true);
+
+            // write this service description file
+            Map<String, Object> thisServiceEoModelMap = 
createEoModelMap(callingServiceSet, calledServiceSet, callingServiceEcaSet,
+                    calledServiceEcaSet,
+                    useMoreDetailedNames);
+            UtilPlist.writePlistFile(thisServiceEoModelMap, eomodeldFullPath, 
this.modelService.getName() + ".plist", true);
+
+            // write service description files
+            if (callingServiceSet != null) {
+                for (ServiceArtifactInfo callingService : callingServiceSet) {
+                    Map<String, Object> serviceEoModelMap = 
callingService.createEoModelMap(null, UtilMisc.toSet(this), null, null,
+                            useMoreDetailedNames);
+                    UtilPlist.writePlistFile(serviceEoModelMap, 
eomodeldFullPath, callingService.getDisplayPrefixedName() + ".plist", true);
+                }
+            }
+            if (calledServiceSet != null) {
+                for (ServiceArtifactInfo calledService : calledServiceSet) {
+                    Map<String, Object> serviceEoModelMap = 
calledService.createEoModelMap(UtilMisc.toSet(this), null, null, null,
+                            useMoreDetailedNames);
+                    UtilPlist.writePlistFile(serviceEoModelMap, 
eomodeldFullPath, calledService.getDisplayPrefixedName() + ".plist", true);
+                }
             }
-        }
 
-        // write SECA description files
-        if (callingServiceEcaSet != null) {
+            // write SECA description files
             for (ServiceEcaArtifactInfo callingServiceEca: 
callingServiceEcaSet) {
                 // add List<ServiceArtifactInfo> for services that trigger 
this eca rule
                 Set<ServiceArtifactInfo> ecaCallingServiceSet = 
callingServiceEca.getServicesTriggeringServiceEca();
@@ -524,8 +527,6 @@ public class ServiceArtifactInfo extends ArtifactInfoBase {
                 Map<String, Object> serviceEcaEoModelMap = 
callingServiceEca.createEoModelMap(ecaCallingServiceSet, null, 
useMoreDetailedNames);
                 UtilPlist.writePlistFile(serviceEcaEoModelMap, 
eomodeldFullPath, callingServiceEca.getDisplayPrefixedName() + ".plist", true);
             }
-        }
-        if (calledServiceEcaSet != null) {
             for (ServiceEcaArtifactInfo calledServiceEca: calledServiceEcaSet) 
{
                 // add List<ServiceArtifactInfo> for services this eca rule 
calls in action
                 Set<ServiceArtifactInfo> ecaCalledServiceSet = 
calledServiceEca.getServicesCalledByServiceEcaActions();
diff --git 
a/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroScreenRenderer.java
 
b/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroScreenRenderer.java
index d8843fc..0eb198c 100644
--- 
a/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroScreenRenderer.java
+++ 
b/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroScreenRenderer.java
@@ -719,9 +719,9 @@ public class MacroScreenRenderer implements 
ScreenStringRenderer {
         if (subWidget.equals(screenlet.getNavigationForm())) {
             HttpServletRequest request = (HttpServletRequest) 
context.get("request");
             HttpServletResponse response = (HttpServletResponse) 
context.get("response");
-            VisualTheme visualTheme = UtilHttp.getVisualTheme(request);
-            ModelTheme modelTheme = visualTheme.getModelTheme();
             if (request != null && response != null) {
+                VisualTheme visualTheme = UtilHttp.getVisualTheme(request);
+                ModelTheme modelTheme = visualTheme.getModelTheme();
                 Map<String, Object> globalCtx = 
UtilGenerics.cast(context.get("globalContext"));
                 globalCtx.put("NO_PAGINATOR", true);
                 FormStringRenderer savedRenderer = (FormStringRenderer) 
context.get("formStringRenderer");

Reply via email to