You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by mb...@apache.org on 2017/12/08 20:49:28 UTC

svn commit: r1817562 - in /ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util: EntityCrypto.java EntityDataLoader.java EntityQuery.java EntitySaxReader.java SequenceUtil.java

Author: mbrohl
Date: Fri Dec  8 20:49:28 2017
New Revision: 1817562

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

Thanks Julian Leichert for reporting and providing the patch.

Modified:
    ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityCrypto.java
    ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityDataLoader.java
    ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityQuery.java
    ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntitySaxReader.java
    ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/SequenceUtil.java

Modified: ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityCrypto.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityCrypto.java?rev=1817562&r1=1817561&r2=1817562&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityCrypto.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityCrypto.java Fri Dec  8 20:49:28 2017
@@ -33,6 +33,7 @@ import org.apache.ofbiz.base.crypto.Hash
 import org.apache.ofbiz.base.util.Debug;
 import org.apache.ofbiz.base.util.GeneralException;
 import org.apache.ofbiz.base.util.StringUtil;
+import org.apache.ofbiz.base.util.UtilIO;
 import org.apache.ofbiz.base.util.UtilObject;
 import org.apache.ofbiz.base.util.UtilValidate;
 import org.apache.ofbiz.entity.Delegator;
@@ -51,9 +52,9 @@ public final class EntityCrypto {
 
     public static final String module = EntityCrypto.class.getName();
 
-    protected final Delegator delegator;
-    protected final ConcurrentMap<String, byte[]> keyMap = new ConcurrentHashMap<String, byte[]>();
-    protected final StorageHandler[] handlers;
+    private final Delegator delegator;
+    private final ConcurrentMap<String, byte[]> keyMap = new ConcurrentHashMap<String, byte[]>();
+    private final StorageHandler[] handlers;
 
     public EntityCrypto(Delegator delegator, String kekText) throws EntityCryptoException {
         this.delegator = delegator;
@@ -379,7 +380,7 @@ public final class EntityCrypto {
 
         @Override
         protected String getHashedKeyName(String originalKeyName) {
-            return HashCrypt.digestHash64("SHA", originalKeyName.getBytes());
+            return HashCrypt.digestHash64("SHA", originalKeyName.getBytes(UtilIO.getUtf8()));
         }
 
         @Override

Modified: ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityDataLoader.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityDataLoader.java?rev=1817562&r1=1817561&r2=1817562&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityDataLoader.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityDataLoader.java Fri Dec  8 20:49:28 2017
@@ -19,10 +19,12 @@
 package org.apache.ofbiz.entity.util;
 
 import java.io.File;
+import java.io.IOException;
 import java.net.URL;
 import java.util.Collections;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.Locale;
 import java.util.StringTokenizer;
 
 import org.apache.ofbiz.base.component.ComponentConfig;
@@ -48,6 +50,7 @@ import org.apache.ofbiz.entity.model.Mod
 import org.apache.ofbiz.entity.model.ModelUtil;
 import org.apache.ofbiz.entity.model.ModelViewEntity;
 import org.w3c.dom.Element;
+import org.xml.sax.SAXException;
 
 /**
  * Some utility routines for loading seed data.
@@ -105,7 +108,7 @@ public class EntityDataLoader {
                     throw new IllegalArgumentException("Reader name list does not contain String(s) or Element(s)");
                 }
                 readerName = readerName.trim();
-                
+
                 // ignore the "tenant" reader if multitenant is disabled
                 if ("tenant".equals(readerName) && !EntityUtil.isMultiTenantEnabled()) {
                     continue;
@@ -160,14 +163,16 @@ public class EntityDataLoader {
         if (UtilValidate.isNotEmpty(paths)) {
             StringTokenizer tokenizer = new StringTokenizer(paths, ";");
             while (tokenizer.hasMoreTokens()) {
-                String path = tokenizer.nextToken().toLowerCase();
+                String path = tokenizer.nextToken().toLowerCase(Locale.getDefault());
                 File loadDir = new File(path);
                 if (loadDir.exists() && loadDir.isDirectory()) {
                     File[] files = loadDir.listFiles();
                     List<File> tempFileList = new LinkedList<File>();
-                    for (File file: files) {
-                        if (file.getName().toLowerCase().endsWith(".xml")) {
-                            tempFileList.add(file);
+                    if (files != null) {
+                        for (File file : files) {
+                            if (file.getName().toLowerCase(Locale.getDefault()).endsWith(".xml")) {
+                                tempFileList.add(file);
+                            }
                         }
                     }
                     Collections.sort(tempFileList);
@@ -214,7 +219,7 @@ public class EntityDataLoader {
             if ("tenant".equals(readerName) && "N".equals(UtilProperties.getPropertyValue("general", "multitenant"))) {
                 continue;
             }
-            
+
             readerNames.add(readerName);
         }
         return getUrlByComponentList(helperName, components, readerNames);
@@ -261,7 +266,7 @@ public class EntityDataLoader {
             reader.setMaintainTxStamps(maintainTxs);
             reader.setContinueOnFail(continueOnFail);
             rowsChanged += reader.parse(dataUrl);
-        } catch (Exception e) {
+        } catch (IOException | SAXException e) {
             String xmlError = "[loadData]: Error loading XML Resource \"" + dataUrl.toExternalForm() + "\"; Error was: " + e.getMessage();
             errorMessages.add(xmlError);
             if (continueOnFail) {

Modified: ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityQuery.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityQuery.java?rev=1817562&r1=1817561&r2=1817562&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityQuery.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityQuery.java Fri Dec  8 20:49:28 2017
@@ -459,7 +459,7 @@ public class EntityQuery {
         }
         return result;
     }
-    
+
     private EntityFindOptions makeEntityFindOptions() {
         EntityFindOptions findOptions = new EntityFindOptions();
         if (resultSetType != null) {

Modified: ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntitySaxReader.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntitySaxReader.java?rev=1817562&r1=1817561&r2=1817562&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntitySaxReader.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntitySaxReader.java Fri Dec  8 20:49:28 2017
@@ -18,11 +18,11 @@
  *******************************************************************************/
 package org.apache.ofbiz.entity.util;
 
+import java.io.BufferedReader;
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
-import java.io.Reader;
 import java.io.StringWriter;
 import java.net.MalformedURLException;
 import java.net.URL;
@@ -40,6 +40,7 @@ import javax.xml.parsers.SAXParserFactor
 import org.apache.ofbiz.base.location.FlexibleLocation;
 import org.apache.ofbiz.base.util.Base64;
 import org.apache.ofbiz.base.util.Debug;
+import org.apache.ofbiz.base.util.UtilIO;
 import org.apache.ofbiz.base.util.UtilMisc;
 import org.apache.ofbiz.base.util.UtilValidate;
 import org.apache.ofbiz.base.util.UtilXml;
@@ -239,7 +240,7 @@ public class EntitySaxReader extends Def
                     valuesToDelete.clear();
                 }
                 TransactionUtil.commit(beganTransaction);
-            } catch (Exception e) {
+            } catch (GenericEntityException | IOException | IllegalArgumentException | SAXException e) {
                 String errMsg = "An error occurred saving the data, rolling back transaction (" + beganTransaction + ")";
                 Debug.logError(e, errMsg, module);
                 TransactionUtil.rollback(beganTransaction, errMsg, e);
@@ -318,7 +319,7 @@ public class EntitySaxReader extends Def
                 throw new SAXException("Could not find transform template with resource path: " + templatePath);
             } else {
                 try {
-                    Reader templateReader = new InputStreamReader(templateUrl.openStream());
+                    BufferedReader templateReader = new BufferedReader(new InputStreamReader(templateUrl.openStream(),UtilIO.getUtf8()));
 
                     StringWriter outWriter = new StringWriter();
                     Configuration config = FreeMarkerWorker.newConfiguration();

Modified: ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/SequenceUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/SequenceUtil.java?rev=1817562&r1=1817561&r2=1817562&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/SequenceUtil.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/SequenceUtil.java Fri Dec  8 20:49:28 2017
@@ -222,7 +222,7 @@ public class SequenceUtil {
 
                             }
                         }
-                        // 2 - select the record (now locked) to get the curSeqId
+                        // 2 - select the record (now locked) to get thec curSeqId
                         rs = stmt.executeQuery(selectSequenceStatement);
                         boolean sequenceFound = rs.next();
                         if (sequenceFound) {
@@ -250,12 +250,12 @@ public class SequenceUtil {
                             Debug.logWarning(sqle, "Error closing statement in sequence util", module);
                         }
                         try {
-                            if (connection != null) connection.close();
+                            connection.close();
                         } catch (SQLException sqle) {
                             Debug.logWarning(sqle, "Error closing connection in sequence util", module);
                         }
                     }
-                } catch (Exception e) {
+                } catch (SQLException | GenericEntityException  e) {
                     // reset the sequence fields and return (note: it would be better to throw an exception)
                     curSeqId = 0;
                     maxSeqId = 0;