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/10/12 22:29:10 UTC

svn commit: r1812059 - /ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/

Author: mbrohl
Date: Thu Oct 12 22:29:10 2017
New Revision: 1812059

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

Thanks Julian Leichert for reporting and providing the patch.

Modified:
    ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/Base64.java
    ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/Debug.java
    ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/FileUtil.java
    ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/GroovyUtil.java
    ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/HttpClient.java
    ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/HttpRequestFileUpload.java
    ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/JNDIContextFactory.java
    ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/KeyStoreUtil.java
    ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/MultiTrustManager.java
    ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/ObjectType.java
    ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/RMIExtendedSocketFactory.java
    ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/SSLUtil.java
    ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/ScriptUtil.java
    ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/StringUtil.java
    ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/TimeDuration.java
    ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilDateTime.java
    ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilFormatOut.java
    ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java
    ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilJavaParse.java
    ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilMisc.java
    ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilNumber.java
    ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilProperties.java
    ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilTimer.java
    ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilURL.java
    ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilValidate.java
    ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilXml.java

Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/Base64.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/Base64.java?rev=1812059&r1=1812058&r2=1812059&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/Base64.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/Base64.java Thu Oct 12 22:29:10 2017
@@ -25,7 +25,7 @@ package org.apache.ofbiz.base.util;
 
 public class Base64 {
 
-    private static byte[] Base64EncMap, Base64DecMap;
+    private static byte[] base64EncMap, base64DecMap;
     static {
         // rfc-2045: Base64 Alphabet
         byte[] map =
@@ -94,10 +94,10 @@ public class Base64 {
                 (byte) '9',
                 (byte) '+',
                 (byte) '/' };
-        Base64EncMap = map;
-        Base64DecMap = new byte[128];
-        for (int idx = 0; idx < Base64EncMap.length; idx++) {
-            Base64DecMap[Base64EncMap[idx]] = (byte) idx;
+        base64EncMap = map;
+        base64DecMap = new byte[128];
+        for (int idx = 0; idx < base64EncMap.length; idx++) {
+            base64DecMap[base64EncMap[idx]] = (byte) idx;
         }
     }
 
@@ -110,7 +110,7 @@ public class Base64 {
      */
     public final static byte[] base64Decode(byte[] data) {
         if (data == null) {
-            return null;
+            return new byte[0];
         }
 
         int tail = data.length;
@@ -122,7 +122,7 @@ public class Base64 {
 
         // ascii printable to 0-63 conversion
         for (int idx = 0; idx < data.length; idx++) {
-            data[idx] = Base64DecMap[data[idx]];
+            data[idx] = base64DecMap[data[idx]];
         }
 
         // 4-byte to 3-byte conversion
@@ -151,8 +151,8 @@ public class Base64 {
      */
     public final static String base64Decode(String str) {
         if (str == null) return null;
-        
-        return new String(base64Decode(str.getBytes()));
+
+        return new String(base64Decode(str.getBytes(UtilIO.getUtf8())));
     }
 
     /**
@@ -164,7 +164,7 @@ public class Base64 {
      */
     public final static byte[] base64Encode(byte[] data) {
         if (data == null) {
-            return null;
+            return new byte[0];
         }
 
         int sidx, didx;
@@ -172,18 +172,18 @@ public class Base64 {
 
         // 3-byte to 4-byte conversion + 0-63 to ascii printable conversion
         for (sidx = 0, didx = 0; sidx < data.length - 2; sidx += 3) {
-            dest[didx++] = Base64EncMap[(data[sidx] >>> 2) & 077];
-            dest[didx++] = Base64EncMap[(data[sidx + 1] >>> 4) & 017 | (data[sidx] << 4) & 077];
-            dest[didx++] = Base64EncMap[(data[sidx + 2] >>> 6) & 003 | (data[sidx + 1] << 2) & 077];
-            dest[didx++] = Base64EncMap[data[sidx + 2] & 077];
+            dest[didx++] = base64EncMap[(data[sidx] >>> 2) & 077];
+            dest[didx++] = base64EncMap[(data[sidx + 1] >>> 4) & 017 | (data[sidx] << 4) & 077];
+            dest[didx++] = base64EncMap[(data[sidx + 2] >>> 6) & 003 | (data[sidx + 1] << 2) & 077];
+            dest[didx++] = base64EncMap[data[sidx + 2] & 077];
         }
         if (sidx < data.length) {
-            dest[didx++] = Base64EncMap[(data[sidx] >>> 2) & 077];
+            dest[didx++] = base64EncMap[(data[sidx] >>> 2) & 077];
             if (sidx < data.length - 1) {
-                dest[didx++] = Base64EncMap[(data[sidx + 1] >>> 4) & 017 | (data[sidx] << 4) & 077];
-                dest[didx++] = Base64EncMap[(data[sidx + 1] << 2) & 077];
+                dest[didx++] = base64EncMap[(data[sidx + 1] >>> 4) & 017 | (data[sidx] << 4) & 077];
+                dest[didx++] = base64EncMap[(data[sidx + 1] << 2) & 077];
             } else
-                dest[didx++] = Base64EncMap[(data[sidx] << 4) & 077];
+                dest[didx++] = base64EncMap[(data[sidx] << 4) & 077];
         }
 
         // add padding
@@ -205,6 +205,6 @@ public class Base64 {
         if (str == null) {
             return null;
         }
-        return new String(base64Encode(str.getBytes()));
+        return new String(base64Encode(str.getBytes(UtilIO.getUtf8())));
     }
 }

Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/Debug.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/Debug.java?rev=1812059&r1=1812058&r2=1812059&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/Debug.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/Debug.java Thu Oct 12 22:29:10 2017
@@ -20,6 +20,7 @@ package org.apache.ofbiz.base.util;
 
 import java.util.Formatter;
 import java.util.HashMap;
+import java.util.Locale;
 import java.util.Map;
 import java.util.Properties;
 
@@ -86,7 +87,7 @@ public final class Debug {
     /** Gets an Integer representing the level number from a String representing the level name; will return null if not found */
     public static Integer getLevelFromString(String levelName) {
         if (levelName == null) return null;
-        return levelStringMap.get(levelName.toLowerCase());
+        return levelStringMap.get(levelName.toLowerCase(Locale.getDefault()));
     }
 
     public static void log(int level, Throwable t, String msg, String module) {

Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/FileUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/FileUtil.java?rev=1812059&r1=1812058&r2=1812059&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/FileUtil.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/FileUtil.java Thu Oct 12 22:29:10 2017
@@ -22,13 +22,16 @@ import java.io.BufferedOutputStream;
 import java.io.BufferedReader;
 import java.io.BufferedWriter;
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.FileReader;
 import java.io.FileWriter;
 import java.io.FilenameFilter;
 import java.io.IOException;
+import java.io.InputStreamReader;
 import java.io.OutputStream;
+import java.io.OutputStreamWriter;
 import java.io.Reader;
 import java.io.Writer;
 import java.net.MalformedURLException;
@@ -147,21 +150,13 @@ public final class FileUtil {
     }
 
     public static void writeString(String path, String name, String s) throws IOException {
-        Writer out = getBufferedWriter(path, name);
 
-        try {
+        try (
+        Writer out = getBufferedWriter(path, name);
+        ) {
             out.write(s + System.getProperty("line.separator"));
         } catch (IOException e) {
             Debug.logError(e, module);
-            throw e;
-        } finally {
-            if (out != null) {
-                try {
-                    out.close();
-                } catch (IOException e) {
-                    Debug.logError(e, module);
-                }
-            }
         }
     }
 
@@ -203,7 +198,7 @@ public final class FileUtil {
             throw new IOException("Cannot obtain buffered writer for an empty filename!");
         }
 
-        return new BufferedWriter(new FileWriter(fileName));
+        return new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), UtilIO.getUtf8()));
     }
 
     public static OutputStream getBufferedOutputStream(String path, String name) throws IOException {
@@ -245,9 +240,9 @@ public final class FileUtil {
         }
 
         StringBuffer buf = new StringBuffer();
-        BufferedReader in = null;
-        try {
-            in = new BufferedReader(new FileReader(file));
+        try (
+                BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file), UtilIO
+                        .getUtf8()));) {
 
             String str;
             while ((str = in.readLine()) != null) {
@@ -258,15 +253,6 @@ public final class FileUtil {
             }
         } catch (IOException e) {
             Debug.logError(e, module);
-            throw e;
-        } finally {
-            if (in != null) {
-                try {
-                    in.close();
-                } catch (IOException e) {
-                    Debug.logError(e, module);
-                }
-            }
         }
 
         return buf;
@@ -386,17 +372,16 @@ public final class FileUtil {
    public static boolean containsString(final String fileName, final String searchString) throws IOException {
        File inFile = new File(fileName);
        if (inFile.exists()) {
-           BufferedReader in = new BufferedReader(new FileReader(inFile));
-           try {
+            try (
+           BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(inFile),UtilIO.getUtf8()));
+            ) {
                return containsString(in, searchString);
-           } finally {
-               if (in != null)in.close();
            }
        } else {
            return false;
        }
    }
-   
+
    /**
    *
    *
@@ -411,5 +396,5 @@ public final class FileUtil {
        File f = new File(fileName);
        return f.isFile();
    }
-   
+
 }

Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/GroovyUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/GroovyUtil.java?rev=1812059&r1=1812058&r2=1812059&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/GroovyUtil.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/GroovyUtil.java Thu Oct 12 22:29:10 2017
@@ -168,6 +168,8 @@ public class GroovyUtil {
                 }
             }
             return scriptClass;
+        } catch (RuntimeException e) {
+            throw e;
         } catch (Exception e) {
             throw new GeneralException("Error loading Groovy script at [" + location + "]: ", e);
         }

Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/HttpClient.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/HttpClient.java?rev=1812059&r1=1812058&r2=1812059&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/HttpClient.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/HttpClient.java Thu Oct 12 22:29:10 2017
@@ -29,6 +29,7 @@ import java.net.URLConnection;
 import java.security.cert.CertificateException;
 import java.util.HashMap;
 import java.util.List;
+import java.util.Locale;
 import java.util.Map;
 
 /**
@@ -365,7 +366,7 @@ public class HttpClient {
             if (Debug.verboseOn() || debug) Debug.logVerbose("Content-Type: " + contentType, module);
 
             if (contentType != null) {
-                contentType = contentType.toUpperCase();
+                contentType = contentType.toUpperCase(Locale.getDefault());
                 int charsetEqualsLoc = contentType.indexOf("=", contentType.indexOf("CHARSET"));
                 int afterSemiColon = contentType.indexOf(";", charsetEqualsLoc);
                 if (charsetEqualsLoc >= 0 && afterSemiColon >= 0) {
@@ -378,7 +379,9 @@ public class HttpClient {
                 if (Debug.verboseOn() || debug) Debug.logVerbose("Getting text from HttpClient with charset: " + charset, module);
             }
 
-            BufferedReader post = new BufferedReader(charset == null ? new InputStreamReader(in) : new InputStreamReader(in, charset));
+            try (
+                    BufferedReader post = new BufferedReader(charset == null ? new InputStreamReader(in)
+                            : new InputStreamReader(in, charset))) {
             String line = "";
 
             if (Debug.verboseOn() || debug) Debug.logVerbose("---- HttpClient Response Content ----", module);
@@ -389,6 +392,9 @@ public class HttpClient {
                     buf.append("\n");
                 }
             }
+            }
+        } catch (RuntimeException e) {
+            throw e;
         } catch (Exception e) {
             throw new HttpClientException("Error processing input stream", e);
         }
@@ -476,17 +482,21 @@ public class HttpClient {
             }
 
             if (method.equalsIgnoreCase("post")) {
-                OutputStreamWriter out = new OutputStreamWriter(con.getOutputStream(), this.streamCharset != null ? this.streamCharset : "UTF-8");
-                if (Debug.verboseOn() || debug) Debug.logVerbose("Opened output stream", module);
+                try (
+                        OutputStreamWriter out = new OutputStreamWriter(con.getOutputStream(),
+                                this.streamCharset != null ? this.streamCharset : "UTF-8")) {
+                    if (Debug.verboseOn() || debug)
+                        Debug.logVerbose("Opened output stream", module);
+
+                    if (arguments != null) {
+                        out.write(arguments);
+                        if (Debug.verboseOn() || debug)
+                            Debug.logVerbose("Wrote arguements (parameters) : " + arguments, module);
+                    }
 
-                if (arguments != null) {
-                    out.write(arguments);
-                    if (Debug.verboseOn() || debug) Debug.logVerbose("Wrote arguements (parameters) : " + arguments, module);
+                    if (Debug.verboseOn() || debug)
+                        Debug.logVerbose("Flushed and closed buffer", module);
                 }
-
-                out.flush();
-                out.close();
-                if (Debug.verboseOn() || debug) Debug.logVerbose("Flushed and closed buffer", module);
             }
 
             if (Debug.verboseOn() || debug) {
@@ -501,6 +511,8 @@ public class HttpClient {
                 return sendHttpRequestStream(method, true);
             }
             throw new HttpClientException("IO Error processing request", ioe);
+        } catch (RuntimeException e) {
+            throw e;
         } catch (Exception e) {
             throw new HttpClientException("Error processing request", e);
         }

Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/HttpRequestFileUpload.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/HttpRequestFileUpload.java?rev=1812059&r1=1812058&r2=1812059&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/HttpRequestFileUpload.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/HttpRequestFileUpload.java Thu Oct 12 22:29:10 2017
@@ -30,12 +30,13 @@ import java.util.Map;
 import javax.servlet.ServletInputStream;
 import javax.servlet.http.HttpServletRequest;
 
+
 /**
  * HttpRequestFileUpload - Receive a file upload through an HttpServletRequest
  *
  */
 public class HttpRequestFileUpload {
-
+    private static final String module = HttpRequestFileUpload.class.getName();
     private int BUFFER_SIZE = 4096;
     private int WAIT_INTERVAL = 200; // in milliseconds
     private int MAX_WAITS = 20;
@@ -115,7 +116,7 @@ public class HttpRequestFileUpload {
         int requestLength = 0;
 
         try {
-            requestLength = Integer.valueOf(reqLengthString).intValue();
+            requestLength = Integer.parseInt(reqLengthString);
         } catch (Exception e2) {
             e2.printStackTrace();
             return;
@@ -130,7 +131,7 @@ public class HttpRequestFileUpload {
             return;
         int boundaryLength = i - 2;
 
-        String boundary = new String(line, 0, boundaryLength); // -2 discards the newline character
+        String boundary = new String(line, 0, boundaryLength, UtilIO.getUtf8()); // -2 discards the newline character
 
         System.out.println("boundary=[" + boundary + "] length is " + boundaryLength);
         fields = new HashMap<String, String>();
@@ -139,23 +140,22 @@ public class HttpRequestFileUpload {
             String newLine = "";
 
             if (i > -1) {
-                newLine = new String(line, 0, i);
+                newLine = new String(line, 0, i, UtilIO.getUtf8());
             }
             if (newLine.startsWith("Content-Disposition: form-data; name=\"")) {
                 if (newLine.indexOf("filename=\"") != -1) {
-                    setFilename(new String(line, 0, i - 2));
+                    setFilename(new String(line, 0, i - 2, UtilIO.getUtf8()));
                     if (filename == null)
                         return;
                     // this is the file content
                     i = waitingReadLine(in, line, 0, BUFFER_SIZE, requestLength);
                     requestLength -= i;
 
-                    setContentType(new String(line, 0, i - 2));
+                    setContentType(new String(line, 0, i - 2, UtilIO.getUtf8()));
 
                     // blank line
                     i = waitingReadLine(in, line, 0, BUFFER_SIZE, requestLength);
                     requestLength -= i;
-                    newLine = new String(line, 0, i);
                     String filenameToUse = filename;
 
                     if (overrideFilename != null) {
@@ -165,8 +165,6 @@ public class HttpRequestFileUpload {
                     // first line of actual file
                     i = waitingReadLine(in, line, 0, BUFFER_SIZE, requestLength);
                     requestLength -= i;
-                    newLine = new String(line, 0, i);
-
                     byte[] lastTwoBytes = new byte[2];
 
                     if (i > 1) {
@@ -175,51 +173,63 @@ public class HttpRequestFileUpload {
                     }
                     System.out.println("about to create a file:" + (savePath == null ? "" : savePath) + filenameToUse);
                     // before creating the file make sure directory exists
+                    if (savePath == null) {
+                        throw new IllegalArgumentException("savePath is null");
+                    }
                     File savePathFile = new File(savePath);
                     if (!savePathFile.exists()) {
-                        savePathFile.mkdirs();
-                    }
-                    FileOutputStream fos = new FileOutputStream((savePath == null ? "" : savePath) + filenameToUse);
-                    boolean bail = (new String(line, 0, i).startsWith(boundary));
-                    boolean oneByteLine = (i == 1); // handle one-byte lines
-
-                    while ((requestLength > 0/* i != -1*/) && !bail) {
-
-                        // write the current buffer, except the last 2 bytes;
-                        if (i > 1) {
-                            fos.write(line, 0, i - 2);
-                        }
-
-                        oneByteLine = (i == 1); // we need to track on-byte lines differently
-
-                        i = waitingReadLine(in, line, 0, BUFFER_SIZE, requestLength);
-                        requestLength -= i;
-
-                        // the problem is the last line of the file content
-                        // contains the new line character.
-
-                        // if the line just read was the last line, we're done.
-                        // if not, we must write the last 2 bytes of the previous buffer
-                        // just assume that a one-byte line isn't the last line
-
-                        if (requestLength < 1) {
-                            bail = true;
-                        } else if (oneByteLine) {
-                            fos.write(lastTwoBytes, 0, 1); // we only saved one byte
-                        } else {
-                            fos.write(lastTwoBytes, 0, 2);
+                        if (!savePathFile.mkdirs()) {
+                            Debug.logError("Directory could not be created", filenameToUse);
                         }
 
-                        if (i > 1) {
-                            // save the last 2 bytes of the buffer
-                            lastTwoBytes[0] = line[i - 2];
-                            lastTwoBytes[1] = line[i - 1];
-                        } else {
-                            lastTwoBytes[0] = line[0]; // only save one byte
+                    }
+                    try (
+                            FileOutputStream fos = new FileOutputStream(savePath + filenameToUse);) {
+                        boolean bail = (new String(line, 0, i, UtilIO.getUtf8()).startsWith(boundary));
+                        boolean oneByteLine = (i == 1); // handle one-byte lines
+
+                        while ((requestLength > 0/* i != -1 */) && !bail) {
+
+                            // write the current buffer, except the last 2 bytes;
+                            if (i > 1) {
+                                fos.write(line, 0, i - 2);
+                            }
+
+                            oneByteLine = (i == 1); // we need to track on-byte lines differently
+
+                            i = waitingReadLine(in, line, 0, BUFFER_SIZE, requestLength);
+                            requestLength -= i;
+
+                            // the problem is the last line of the file content
+                            // contains the new line character.
+
+                            // if the line just read was the last line, we're done.
+                            // if not, we must write the last 2 bytes of the previous buffer
+                            // just assume that a one-byte line isn't the last line
+
+                            if (requestLength < 1) {
+                                bail = true;
+                            } else if (oneByteLine) {
+                                fos.write(lastTwoBytes, 0, 1); // we only saved one byte
+                            } else {
+                                fos.write(lastTwoBytes, 0, 2);
+                            }
+
+                            if (i > 1) {
+                                // save the last 2 bytes of the buffer
+                                lastTwoBytes[0] = line[i - 2];
+                                lastTwoBytes[1] = line[i - 1];
+                            } else {
+                                lastTwoBytes[0] = line[0]; // only save one byte
+                            }
                         }
+                        fos.flush();
+                        fos.close();
+                    } catch (RuntimeException e) {
+                        throw e;
+                    } catch (Exception e) {
+                        Debug.logError(e, module);
                     }
-                    fos.flush();
-                    fos.close();
                 } else {
                     // this is a field
                     // get the field name
@@ -231,7 +241,7 @@ public class HttpRequestFileUpload {
                     requestLength -= i;
                     i = waitingReadLine(in, line, 0, BUFFER_SIZE, requestLength);
                     requestLength -= i;
-                    newLine = new String(line, 0, i);
+                    newLine = new String(line, 0, i, UtilIO.getUtf8());
                     StringBuilder fieldValue = new StringBuilder(BUFFER_SIZE);
 
                     while (requestLength > 0/* i != -1*/ && !newLine.startsWith(boundary)) {
@@ -246,7 +256,7 @@ public class HttpRequestFileUpload {
                             fieldValue.append(newLine.substring(0, newLine.length() - 2));
                         else
                             fieldValue.append(newLine);
-                        newLine = new String(line, 0, i);
+                        newLine = new String(line, 0, i, UtilIO.getUtf8());
                     }
                     fields.put(fieldName, fieldValue.toString());
                 }

Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/JNDIContextFactory.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/JNDIContextFactory.java?rev=1812059&r1=1812058&r2=1812059&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/JNDIContextFactory.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/JNDIContextFactory.java Thu Oct 12 22:29:10 2017
@@ -76,9 +76,7 @@ public class JNDIContextFactory {
                 throw new GenericConfigException(errorMsg, e);
             }
 
-            if (ic != null) {
-                ic = contexts.putIfAbsentAndGet(jndiServerName, ic);
-            }
+            ic = contexts.putIfAbsentAndGet(jndiServerName, ic);
         }
 
         return ic;

Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/KeyStoreUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/KeyStoreUtil.java?rev=1812059&r1=1812058&r2=1812059&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/KeyStoreUtil.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/KeyStoreUtil.java Thu Oct 12 22:29:10 2017
@@ -31,6 +31,7 @@ import java.io.PrintStream;
 import java.io.Reader;
 import java.io.StringReader;
 import java.net.URL;
+import java.nio.charset.StandardCharsets;
 import java.security.GeneralSecurityException;
 import java.security.KeyFactory;
 import java.security.KeyStore;
@@ -187,7 +188,7 @@ public final class KeyStoreUtil {
         byte[] certBuf = cert.getEncoded();
         StringBuilder buf = new StringBuilder();
         buf.append("-----BEGIN CERTIFICATE-----\n");
-        buf.append(new String(Base64.encodeBase64Chunked(certBuf)));
+        buf.append(new String(Base64.encodeBase64Chunked(certBuf), UtilIO.getUtf8()));
         buf.append("\n-----END CERTIFICATE-----\n");
         return buf.toString();
     }
@@ -201,7 +202,7 @@ public final class KeyStoreUtil {
     }
 
     public static Certificate pemToCert(InputStream is) throws IOException, CertificateException {
-        return pemToCert(new InputStreamReader(is));
+        return pemToCert(new InputStreamReader(is, UtilIO.getUtf8()));
     }
 
     public static Certificate pemToCert(Reader r) throws IOException, CertificateException {
@@ -210,7 +211,7 @@ public final class KeyStoreUtil {
 
         BufferedReader reader = new BufferedReader(r);
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        PrintStream ps = new PrintStream(baos);
+        PrintStream ps = new PrintStream(baos, false, UtilIO.getUtf8().toString());
 
         String line;
 

Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/MultiTrustManager.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/MultiTrustManager.java?rev=1812059&r1=1812058&r2=1812059&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/MultiTrustManager.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/MultiTrustManager.java Thu Oct 12 22:29:10 2017
@@ -112,7 +112,6 @@ public class MultiTrustManager implement
     protected boolean isTrusted(X509Certificate[] cert) {
         if (cert != null) {
             X509Certificate[] issuers = this.getAcceptedIssuers();
-            if (issuers != null) {
                 for (X509Certificate issuer: issuers) {
                     for (X509Certificate c: cert) {
                         if (Debug.verboseOn())
@@ -121,7 +120,6 @@ public class MultiTrustManager implement
                             if (Debug.verboseOn())
                                 Debug.logInfo("--- Found trusted cert: " + issuer.getSerialNumber().toString(16) + " : " + issuer.getSubjectX500Principal(), module);
                             return true;
-                        }
                     }
                 }
             }

Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/ObjectType.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/ObjectType.java?rev=1812059&r1=1812058&r2=1812059&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/ObjectType.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/ObjectType.java Thu Oct 12 22:29:10 2017
@@ -21,6 +21,7 @@ package org.apache.ofbiz.base.util;
 import java.io.Serializable;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
+import java.nio.charset.StandardCharsets;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
@@ -118,7 +119,7 @@ public class ObjectType {
         // Handle array classes. Details in http://java.sun.com/j2se/1.5.0/docs/guide/jni/spec/types.html#wp16437
         if (className.endsWith("[]")) {
             if (Character.isLowerCase(className.charAt(0)) && className.indexOf(".") < 0) {
-               String prefix = className.substring(0, 1).toUpperCase();
+                String prefix = className.substring(0, 1).toUpperCase(Locale.getDefault());
                // long and boolean have other prefix than first letter
                if (className.startsWith("long")) {
                    prefix = "J";
@@ -526,7 +527,10 @@ public class ObjectType {
         Converter<Object, Object> converter = null;
         try {
             converter = (Converter<Object, Object>) Converters.getConverter(sourceClass, targetClass);
-        } catch (ClassNotFoundException e) {}
+        } catch (ClassNotFoundException e) {
+            Debug.logError(e, module);
+        }
+
         if (converter != null) {
             if (converter instanceof LocalizedConverter) {
                 @SuppressWarnings("rawtypes")

Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/RMIExtendedSocketFactory.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/RMIExtendedSocketFactory.java?rev=1812059&r1=1812058&r2=1812059&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/RMIExtendedSocketFactory.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/RMIExtendedSocketFactory.java Thu Oct 12 22:29:10 2017
@@ -30,19 +30,19 @@ import java.rmi.server.RMISocketFactory;
  * on a specified network interface.  
  */
 public class RMIExtendedSocketFactory extends RMISocketFactory {
-    
+
     /**
      * The network interface to bind the <code>ServerSocket</code> to. If null than bind to all interfaces.
      */
     private InetAddress hostInetAddress;
-    
+
     /**
      * Default constructor. Bind the server sockets on all interfaces.
      */
     public RMIExtendedSocketFactory() {
         // leave hostInetAddress null
     }
-    
+
     /**
      * Creates a new <code>RMIExtendedSocketFactory</code> which will create <code>ServerSocket</code>s 
      * bound on the specified network interface. 
@@ -61,15 +61,15 @@ public class RMIExtendedSocketFactory ex
      * @throws UnknownHostException If an invalid IP address is provided. 
      */
     public RMIExtendedSocketFactory( String hostIpAddress ) throws UnknownHostException {
-        
+
         // check if host length is at least equal to "0.0.0.0"
         if ( hostIpAddress != null && hostIpAddress.length() >= 7 ) {
             String[] octets = hostIpAddress.split( "\\." );
-            
-            if ( octets == null || octets.length != 4 ) {
+
+            if (octets.length != 4) {
                 throw new UnknownHostException( "Invalid IP address: " + hostIpAddress );
             }
-            
+
             byte[] ipAddr = new byte[4];
             for ( int i = 0; i < octets.length; i++ ) {
                 try {
@@ -78,14 +78,13 @@ public class RMIExtendedSocketFactory ex
                     throw new UnknownHostException( "Invalid IP address: " + hostIpAddress );
                 }
             }
-            
+
             hostInetAddress = InetAddress.getByAddress( ipAddr );
-            
+
         }
-        
-        
+
     }
-    
+
     @Override
     public ServerSocket createServerSocket(int port) throws IOException {
         if ( hostInetAddress !=  null ) {
@@ -97,7 +96,7 @@ public class RMIExtendedSocketFactory ex
 
     @Override
     public Socket createSocket(String host, int port) throws IOException {
-        
+
         return new Socket( host, port );
     }
 

Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/SSLUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/SSLUtil.java?rev=1812059&r1=1812058&r2=1812059&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/SSLUtil.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/SSLUtil.java Thu Oct 12 22:29:10 2017
@@ -112,15 +112,13 @@ public final class SSLUtil {
             Debug.logError(e, module);
         }
 
-        if (mgrs != null) {
-            for (TrustManager mgr: mgrs) {
-                if (mgr instanceof X509TrustManager) {
-                    try {
-                        ((X509TrustManager) mgr).checkClientTrusted(chain, authType);
-                        return true;
-                    } catch (CertificateException e) {
-                        // do nothing; just loop
-                    }
+        for (TrustManager mgr : mgrs) {
+            if (mgr instanceof X509TrustManager) {
+                try {
+                    ((X509TrustManager) mgr).checkClientTrusted(chain, authType);
+                    return true;
+                } catch (CertificateException e) {
+                    // do nothing; just loop
                 }
             }
         }
@@ -135,7 +133,10 @@ public final class SSLUtil {
                 if (ks != null) {
                     List<KeyManager> newKeyManagers = Arrays.asList(getKeyManagers(ks, ksi.getPassword(), alias));
                     keyMgrs.addAll(newKeyManagers);
-                    if (Debug.verboseOn()) Debug.logVerbose("Loaded another cert store, adding [" + (newKeyManagers == null ? "0" : newKeyManagers.size()) + "] KeyManagers for alias [" + alias + "] and keystore: " + ksi.createResourceHandler().getFullLocation(), module);
+                    if (Debug.verboseOn())
+                        Debug.logVerbose("Loaded another cert store, adding [" + newKeyManagers.size()
+                                + "] KeyManagers for alias [" + alias + "] and keystore: " + ksi.createResourceHandler()
+                                        .getFullLocation(), module);
                 } else {
                     throw new IOException("Unable to load keystore: " + ksi.createResourceHandler().getFullLocation());
                 }
@@ -266,6 +267,8 @@ public final class SSLUtil {
 
                             try {
                                 peerCert.checkValidity();
+                            } catch (RuntimeException e) {
+                                throw e;
                             } catch (Exception e) {
                                 // certificate not valid
                                 Debug.logWarning("Certificate is not valid!", module);

Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/ScriptUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/ScriptUtil.java?rev=1812059&r1=1812058&r2=1812059&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/ScriptUtil.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/ScriptUtil.java Thu Oct 12 22:29:10 2017
@@ -19,8 +19,7 @@
 package org.apache.ofbiz.base.util;
 
 import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileReader;
+import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.net.URL;
@@ -137,7 +136,8 @@ public final class ScriptUtil {
             try {
                 Compilable compilableEngine = (Compilable) engine;
                 URL scriptUrl = FlexibleLocation.resolveLocation(filePath);
-                BufferedReader reader = new BufferedReader(new InputStreamReader(scriptUrl.openStream()));
+                BufferedReader reader = new BufferedReader(new InputStreamReader(scriptUrl.openStream(), UtilIO
+                        .getUtf8()));
                 script = compilableEngine.compile(reader);
                 if (Debug.verboseOn()) {
                     Debug.logVerbose("Compiled script " + filePath + " using engine " + engine.getClass().getName(), module);
@@ -370,7 +370,7 @@ public final class ScriptUtil {
             // The test for null can be removed when the engine is fixed.
             CompiledScript script = compileScriptFile(filePath);
             if (script != null) {
-                return executeScript(script, functionName, scriptContext, args);
+                return executeScript(script, null, scriptContext, args);
             }
         }
         String fileExtension = getFileExtension(filePath);
@@ -384,17 +384,21 @@ public final class ScriptUtil {
         }
         engine.setContext(scriptContext);
         URL scriptUrl = FlexibleLocation.resolveLocation(filePath);
-        FileReader reader = new FileReader(new File(scriptUrl.getFile()));
-        Object result = engine.eval(reader);
-        if (UtilValidate.isNotEmpty(functionName)) {
-            try {
-                Invocable invocableEngine = (Invocable) engine;
-                result = invocableEngine.invokeFunction(functionName, args == null ? EMPTY_ARGS : args);
-            } catch (ClassCastException e) {
-                throw new ScriptException("Script engine " + engine.getClass().getName() + " does not support function/method invocations");
+        try (
+                InputStreamReader reader = new InputStreamReader(new FileInputStream(scriptUrl.getFile()), UtilIO
+                        .getUtf8());) {
+            Object result = engine.eval(reader);
+            if (UtilValidate.isNotEmpty(functionName)) {
+                try {
+                    Invocable invocableEngine = (Invocable) engine;
+                    result = invocableEngine.invokeFunction(functionName, args == null ? EMPTY_ARGS : args);
+                } catch (ClassCastException e) {
+                    throw new ScriptException("Script engine " + engine.getClass().getName()
+                            + " does not support function/method invocations");
+                }
             }
+            return result;
         }
-        return result;
     }
 
     private static String getFileExtension(String filePath) {

Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/StringUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/StringUtil.java?rev=1812059&r1=1812058&r2=1812059&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/StringUtil.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/StringUtil.java Thu Oct 12 22:29:10 2017
@@ -235,7 +235,9 @@ public class StringUtil {
             }
 
             try {
-                decodedMap.put(URLDecoder.decode(name, "UTF-8"), URLDecoder.decode(value, "UTF-8"));
+                if (value != null && name != null) {
+                    decodedMap.put(URLDecoder.decode(name, "UTF-8"), URLDecoder.decode(value, "UTF-8"));
+                }
             } catch (UnsupportedEncodingException e1) {
                 Debug.logError(e1, module);
             }

Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/TimeDuration.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/TimeDuration.java?rev=1812059&r1=1812058&r2=1812059&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/TimeDuration.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/TimeDuration.java Thu Oct 12 22:29:10 2017
@@ -176,9 +176,13 @@ public class TimeDuration implements Ser
         }
         try {
             TimeDuration that = (TimeDuration) obj;
-            return this.years == that.years && this.months == that.months && this.days == that.days
-            && this.hours == that.hours && this.minutes == that.minutes && this.seconds == that.seconds
-            && this.milliseconds == that.milliseconds;
+            return this.years == that.years
+                    && this.months == that.months
+                    && this.days == that.days
+                    && this.hours == that.hours
+                    && this.minutes == that.minutes
+                    && this.seconds == that.seconds
+                    && this.milliseconds == that.milliseconds;
         } catch (Exception e) {}
         return false;
     }

Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilDateTime.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilDateTime.java?rev=1812059&r1=1812058&r2=1812059&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilDateTime.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilDateTime.java Thu Oct 12 22:29:10 2017
@@ -39,6 +39,8 @@ import com.ibm.icu.util.Calendar;
  */
 public final class UtilDateTime {
 
+    public static final String module = UtilDateTime.class.getName();
+
     private static final String[][] timevals = {
         {"1000", "millisecond"},
         {"60", "second"},
@@ -114,7 +116,7 @@ public final class UtilDateTime {
     public static String formatInterval(double interval, int count, Locale locale) {
         List<Double> parts = new ArrayList<Double>(timevals.length);
         for (String[] timeval: timevals) {
-            int value = Integer.valueOf(timeval[0]);
+            int value = Integer.parseInt(timeval[0]);
             double remainder = interval % value;
             interval = interval / value;
             parts.add(remainder);
@@ -554,8 +556,8 @@ public final class UtilDateTime {
      */
     public static java.util.Date toDate(String monthStr, String dayStr, String yearStr, String hourStr,
             String minuteStr, String secondStr) {
-        int month, day, year, hour, minute, second;
 
+        int month, day, year, hour, minute, second;
         try {
             month = Integer.parseInt(monthStr);
             day = Integer.parseInt(dayStr);
@@ -564,9 +566,11 @@ public final class UtilDateTime {
             minute = Integer.parseInt(minuteStr);
             second = Integer.parseInt(secondStr);
         } catch (Exception e) {
+            Debug.logError(e, module);
             return null;
         }
         return toDate(month, day, year, hour, minute, second);
+
     }
 
     /**
@@ -683,7 +687,7 @@ public final class UtilDateTime {
         String dateString = toDateString(date);
         String timeString = toTimeString(date);
 
-        if (dateString != null && timeString != null) {
+        if (!dateString.isEmpty() && !timeString.isEmpty()) {
             return dateString + " " + timeString;
         } else {
             return "";
@@ -1220,7 +1224,7 @@ public final class UtilDateTime {
         }
 
     }
-    
+
     public static String getDateFormat() {
         return DATE_FORMAT;
     }

Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilFormatOut.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilFormatOut.java?rev=1812059&r1=1812058&r2=1812059&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilFormatOut.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilFormatOut.java Thu Oct 12 22:29:10 2017
@@ -360,7 +360,7 @@ public final class UtilFormatOut {
                 if (data.length > 5120) {
                     return "[...binary data]";
                 }
-                return new String(Base64.base64Encode(data));
+                return new String(Base64.base64Encode(data), UtilIO.getUtf8());
             }
             return obj1.toString();
         }

Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java?rev=1812059&r1=1812058&r2=1812059&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java Thu Oct 12 22:29:10 2017
@@ -177,9 +177,8 @@ public final class UtilHttp {
                     continue;
                 }
                 int equalsIndex = token.indexOf("=");
-                String name = token;
                 if (equalsIndex > 0) {
-                    name = token.substring(0, equalsIndex);
+                    String name = token.substring(0, equalsIndex);
                     paramMap.put(name, token.substring(equalsIndex + 1));
                 }
             }
@@ -1082,28 +1081,19 @@ public final class UtilHttp {
         }
 
         // initialize the buffered streams
-        BufferedOutputStream bos = new BufferedOutputStream(out, bufferSize);
-        BufferedInputStream bis = new BufferedInputStream(in, bufferSize);
 
         byte[] buffer = new byte[length];
         int read = 0;
-        try {
+        try (
+                BufferedOutputStream bos = new BufferedOutputStream(out, bufferSize);
+                BufferedInputStream bis = new BufferedInputStream(in, bufferSize);
+        ) {
             while ((read = bis.read(buffer, 0, buffer.length)) != -1) {
                 bos.write(buffer, 0, read);
             }
         } catch (IOException e) {
             Debug.logError(e, "Problem reading/writing buffers", module);
-            bis.close();
-            bos.close();
             throw e;
-        } finally {
-            if (bis != null) {
-                bis.close();
-            }
-            if (bos != null) {
-                bos.flush();
-                bos.close();
-            }
         }
     }
 
@@ -1161,12 +1151,14 @@ public final class UtilHttp {
         Map<Integer, Map<String, Object>> rows = new HashMap<Integer, Map<String, Object>>(); // stores the rows keyed by row number
 
         // first loop through all the keys and create a hashmap for each ${ROW_SUBMIT_PREFIX}${N} = Y
-        for (String key: parameters.keySet()) {
+        for (Map.Entry<String, Object> entry : parameters.entrySet()) {
+            String key = entry.getKey();
             // skip everything that is not ${ROW_SUBMIT_PREFIX}N
             if (key == null || key.length() <= ROW_SUBMIT_PREFIX_LENGTH) continue;
             if (key.indexOf(MULTI_ROW_DELIMITER) <= 0) continue;
             if (!key.substring(0, ROW_SUBMIT_PREFIX_LENGTH).equals(ROW_SUBMIT_PREFIX)) continue;
-            if (!parameters.get(key).equals("Y")) continue;
+            if (!entry.getValue().equals("Y"))
+                continue;
 
             // decode the value of N and create a new map for it
             Integer n = Integer.decode(key.substring(ROW_SUBMIT_PREFIX_LENGTH, key.length()));
@@ -1477,6 +1469,8 @@ public final class UtilHttp {
                     .setSSLSocketFactory(sslsf)
                     .build();
             return httpClient;
+        } catch (RuntimeException e) {
+            throw e;
         } catch (Exception e) {
             return HttpClients.createDefault();
         }

Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilJavaParse.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilJavaParse.java?rev=1812059&r1=1812058&r2=1812059&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilJavaParse.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilJavaParse.java Thu Oct 12 22:29:10 2017
@@ -155,7 +155,7 @@ public final class UtilJavaParse {
         int nextOpen = javaFile.indexOf("{", blockStart+1);
         int nextClose = javaFile.indexOf("}", blockStart+1);
         if (nextOpen > 0 && nextClose > 0 && nextClose > nextOpen) {
-            javaFile.substring(nextOpen, nextClose);
+            javaFile = javaFile.substring(nextOpen, nextClose);
         }
         // if no close, end with couldn't find
         if (nextClose < 0) return -1;

Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilMisc.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilMisc.java?rev=1812059&r1=1812058&r2=1812059&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilMisc.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilMisc.java Thu Oct 12 22:29:10 2017
@@ -89,7 +89,11 @@ public final class UtilMisc {
                 return 0;
             }
 
-        } catch (Exception e) {}
+        } catch (RuntimeException e) {
+            throw e;
+        } catch (Exception e) {
+            Debug.log(e, module);
+        }
         return 1;
     }
 
@@ -418,7 +422,7 @@ public final class UtilMisc {
             return (Double) obj;
         }
         if (obj instanceof Number) {
-            return new Double(((Number)obj).doubleValue());
+            return Double.valueOf(((Number) obj).doubleValue());
         }
         Double result = null;
         try {
@@ -482,7 +486,7 @@ public final class UtilMisc {
             return (Long) obj;
         }
         if (obj instanceof Number) {
-            return new Long(((Number)obj).longValue());
+            return Long.valueOf(((Number) obj).longValue());
         }
         Long result = null;
         try {
@@ -592,17 +596,17 @@ public final class UtilMisc {
             throw new IOException("File is a directory, not a file, cannot copy") ;
         } else {
 
-            InputStream in = new FileInputStream(sourceLocation);
-            OutputStream out = new FileOutputStream(targetLocation);
-
-            // Copy the bits from instream to outstream
-            byte[] buf = new byte[1024];
-            int len;
-            while ((len = in.read(buf)) > 0) {
-                out.write(buf, 0, len);
+            try (
+                    InputStream in = new FileInputStream(sourceLocation);
+                    OutputStream out = new FileOutputStream(targetLocation);
+            ) {
+                // Copy the bits from instream to outstream
+                byte[] buf = new byte[1024];
+                int len;
+                while ((len = in.read(buf)) > 0) {
+                    out.write(buf, 0, len);
+                }
             }
-            in.close();
-            out.close();
         }
     }
 

Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilNumber.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilNumber.java?rev=1812059&r1=1812058&r2=1812059&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilNumber.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilNumber.java Thu Oct 12 22:29:10 2017
@@ -27,7 +27,7 @@ import com.ibm.icu.text.RuleBasedNumberF
 
 public final class UtilNumber {
 
-    public static String module = UtilNumber.class.getName();
+    public static final String module = UtilNumber.class.getName();
 
     // properties file name for arithmetic configuration
     private static final String arithmeticPropertiesFile = "arithmetic.properties";
@@ -188,12 +188,10 @@ public final class UtilNumber {
 
         int scale = -1;
         String value = UtilProperties.getPropertyValue(file, property);
-        if (value != null) {
             try {
                 scale = Integer.parseInt(value);
             } catch (NumberFormatException e) {
             }
-        }
         if (scale == -1) {
             Debug.logWarning("Could not set decimal precision from " + property + "=" + value + ". Using default scale of " + DEFAULT_BD_SCALE + ".", module);
             scale = DEFAULT_BD_SCALE;

Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilProperties.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilProperties.java?rev=1812059&r1=1812058&r2=1812059&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilProperties.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilProperties.java Thu Oct 12 22:29:10 2017
@@ -85,7 +85,6 @@ public final class UtilProperties implem
     public static boolean propertyValueEquals(String resource, String name, String compareString) {
         String value = getPropertyValue(resource, name);
 
-        if (value == null) return false;
         return value.trim().equals(compareString);
     }
 
@@ -98,7 +97,6 @@ public final class UtilProperties implem
     public static boolean propertyValueEqualsIgnoreCase(String resource, String name, String compareString) {
         String value = getPropertyValue(resource, name);
 
-        if (value == null) return false;
         return value.trim().equalsIgnoreCase(compareString);
     }
 
@@ -120,9 +118,6 @@ public final class UtilProperties implem
 
     public static double getPropertyNumber(String resource, String name, double defaultValue) {
         String str = getPropertyValue(resource, name);
-        if (str == null) {
-            return defaultValue;
-        }
 
         try {
             return Double.parseDouble(str);
@@ -492,9 +487,9 @@ public final class UtilProperties implem
              return;
          }
 
-         try {
+        try (
+                FileOutputStream propFile = new FileOutputStream(resource);) {
              properties.setProperty(name, value);
-             FileOutputStream propFile = new FileOutputStream(resource);
              if ("XuiLabels".equals(name)) {
                  properties.store(propFile,
                      "##############################################################################\n"
@@ -595,7 +590,7 @@ public final class UtilProperties implem
             Debug.logInfo(name + " misses in " + resource + " for locale " + locale, module);
             return name;
         }
-        return value == null ? name : value.trim();
+        return value.trim();
     }
 
     /** Returns the value of the specified property name from the specified resource/properties file corresponding

Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilTimer.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilTimer.java?rev=1812059&r1=1812058&r2=1812059&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilTimer.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilTimer.java Thu Oct 12 22:29:10 2017
@@ -30,7 +30,7 @@ import java.util.concurrent.ConcurrentHa
 public class UtilTimer {
 
     public static final String module = UtilTimer.class.getName();
-    protected static ConcurrentHashMap<String, UtilTimer> staticTimers = new ConcurrentHashMap<String, UtilTimer>();
+    protected static final ConcurrentHashMap<String, UtilTimer> staticTimers = new ConcurrentHashMap<String, UtilTimer>();
 
     protected String timerName = null;
     protected String lastMessage = null;

Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilURL.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilURL.java?rev=1812059&r1=1812058&r2=1812059&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilURL.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilURL.java Thu Oct 12 22:29:10 2017
@@ -91,8 +91,7 @@ public final class UtilURL {
                 loader = Thread.currentThread().getContextClassLoader();
             } catch (SecurityException e) {
                 // Huh? The new object will be created by the current thread, so how is this any different than the previous code?
-                UtilURL utilURL = new UtilURL();
-                loader = utilURL.getClass().getClassLoader();
+                loader = UtilURL.class.getClassLoader();
             }
         }
         url = loader.getResource(resourceName);

Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilValidate.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilValidate.java?rev=1812059&r1=1812058&r2=1812059&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilValidate.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilValidate.java Thu Oct 12 22:29:10 2017
@@ -20,6 +20,7 @@ package org.apache.ofbiz.base.util;
 
 import java.sql.Timestamp;
 import java.util.Collection;
+import java.util.Locale;
 import java.util.Map;
 
 import org.apache.commons.validator.routines.EmailValidator;
@@ -142,7 +143,7 @@ public final class UtilValidate {
 
     /** An array of ints representing the number of days in each month of the year.
      *  Note: February varies depending on the year */
-    public static final int[] daysInMonth = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
+    static final int[] daysInMonth = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
 
     /** Delimiter for USStateCodes String */
     public static final String USStateCodeDelimiter = "|";
@@ -841,7 +842,7 @@ public final class UtilValidate {
                 calendar.set(yearInt, monthInt - 1, 0, 0, 0, 0);
                 calendar.add(Calendar.MONTH, 1);
                 passed = new java.util.Date(calendar.getTime().getTime());
-            } catch (Exception e) {
+            } catch (NumberFormatException e) {
                 passed = null;
             }
         } else {
@@ -883,7 +884,7 @@ public final class UtilValidate {
                 calendar.set(yearInt, monthInt - 1, 0, 0, 0, 0);
                 calendar.add(Calendar.MONTH, 1);
                 passed = new java.util.Date(calendar.getTime().getTime());
-            } catch (Exception e) {
+            } catch (NumberFormatException e) {
                 passed = null;
             }
         } else {
@@ -1274,7 +1275,7 @@ public final class UtilValidate {
         // "P.0. B"
         // "P0 B"
 
-        String sl = s.toLowerCase();
+        String sl = s.toLowerCase(Locale.getDefault());
         if (sl.indexOf("p.o. b") != -1) return false;
         if (sl.indexOf("p.o.b") != -1) return false;
         if (sl.indexOf("p.o b") != -1) return false;

Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilXml.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilXml.java?rev=1812059&r1=1812058&r2=1812059&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilXml.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilXml.java Thu Oct 12 22:29:10 2017
@@ -35,6 +35,7 @@ import java.util.Set;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import javax.jms.IllegalStateException;
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
@@ -463,15 +464,18 @@ public final class UtilXml {
         Document document = null;
 
         DOMParser parser = new DOMParser() {
-            private XMLLocator locator;
+            private XMLLocator locator = null;
 
             private void setLineColumn(Node node) {
+                if (locator == null) {
+                    throw new java.lang.IllegalStateException("XMLLocator is null");
+                }
                 if (node.getUserData("startLine") != null) {
                     return;
                 }
-                node.setUserData("systemId",locator.getLiteralSystemId(), null);
-                node.setUserData("startLine",locator.getLineNumber(), null);
-                node.setUserData("startColumn",locator.getColumnNumber(), null);
+                node.setUserData("systemId", locator.getLiteralSystemId(), null);
+                node.setUserData("startLine", locator.getLineNumber(), null);
+                node.setUserData("startColumn", locator.getColumnNumber(), null);
             }
 
             private void setLineColumn() {
@@ -825,7 +829,7 @@ public final class UtilXml {
 
                     String value = childElement.getAttribute(attrName);
 
-                    if (value != null && value.equals(attrValue)) {
+                    if (value.equals(attrValue)) {
                         return childElement;
                     }
                 }
@@ -1012,7 +1016,7 @@ public final class UtilXml {
                     if (Debug.verboseOn()) Debug.logVerbose("[UtilXml.LocalResolver.resolveEntity] got LOCAL DTD input source with publicId [" +
                             publicId + "] and the dtd file is [" + dtd + "]", module);
                     return inputSource;
-                } catch (Exception e) {
+                } catch (GeneralException | IOException e) {
                     Debug.logWarning(e, module);
                 }
             } else {