svn commit: r1817963 - in /ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/string: FlexibleStringExpander.java JuelConnector.java UelFunctions.java UelUtil.java

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

svn commit: r1817963 - in /ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/string: FlexibleStringExpander.java JuelConnector.java UelFunctions.java UelUtil.java

mbrohl
Author: mbrohl
Date: Tue Dec 12 22:32:00 2017
New Revision: 1817963

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

There is an Exception being thrown during the tests, reverting and
investigating further.

Modified:
    ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/string/FlexibleStringExpander.java
    ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/string/JuelConnector.java
    ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/string/UelFunctions.java
    ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/string/UelUtil.java

Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/string/FlexibleStringExpander.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/string/FlexibleStringExpander.java?rev=1817963&r1=1817962&r2=1817963&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/string/FlexibleStringExpander.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/string/FlexibleStringExpander.java Tue Dec 12 22:32:00 2017
@@ -31,7 +31,6 @@ import javax.el.PropertyNotFoundExceptio
 import org.apache.ofbiz.base.lang.IsEmpty;
 import org.apache.ofbiz.base.lang.SourceMonitored;
 import org.apache.ofbiz.base.util.Debug;
-import org.apache.ofbiz.base.util.GeneralException;
 import org.apache.ofbiz.base.util.ObjectType;
 import org.apache.ofbiz.base.util.ScriptUtil;
 import org.apache.ofbiz.base.util.UtilDateTime;
@@ -442,8 +441,7 @@ public abstract class FlexibleStringExpa
                     buffer.append(ObjectType.simpleTypeConvert(obj, "String", null, timeZone, locale, true));
                 }
             }
-        } catch (GeneralException | RuntimeException e) {
-            Debug.log(e, module);
+        } catch (Exception e) {
             buffer.append(obj);
         }
         if (buffer.length() > this.hint) {

Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/string/JuelConnector.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/string/JuelConnector.java?rev=1817963&r1=1817962&r2=1817963&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/string/JuelConnector.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/string/JuelConnector.java Tue Dec 12 22:32:00 2017
@@ -78,9 +78,7 @@ public class JuelConnector {
             Object base = null;
             try {
                 base = prefix.eval(bindings, context);
-            } catch (Exception e) {
-                Debug.log(e, module);
-            }
+            } catch (Exception e) {}
             Object property = getProperty(bindings, context);
             if (property == null && strict) {
                 throw new PropertyNotFoundException(LocalMessages.get("error.property.property.notfound", "null", base));
@@ -114,9 +112,7 @@ public class JuelConnector {
             Object base = null;
             try {
                 base = prefix.eval(bindings, context);
-            } catch (Exception e) {
-                Debug.log(e, module);
-            }
+            } catch (Exception e) {}
             Object property = getProperty(bindings, context);
             if (property == null && strict) {
                 throw new PropertyNotFoundException(LocalMessages.get("error.property.property.notfound", "null", base));
@@ -183,7 +179,9 @@ public class JuelConnector {
         public Tree build(String expression) throws ELException {
             try {
                 return new ExtendedParser(this, expression).tree();
-            } catch (ScanException | ParseException e) {
+            } catch (ScanException e) {
+                throw new ELException(LocalMessages.get("error.build", expression, e.getMessage()));
+            } catch (ParseException e) {
                 throw new ELException(LocalMessages.get("error.build", expression, e.getMessage()));
             }
         }

Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/string/UelFunctions.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/string/UelFunctions.java?rev=1817963&r1=1817962&r2=1817963&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/string/UelFunctions.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/string/UelFunctions.java Tue Dec 12 22:32:00 2017
@@ -22,7 +22,6 @@ import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileOutputStream;
-import java.io.IOException;
 import java.io.InputStream;
 import java.lang.reflect.Method;
 import java.net.URL;
@@ -35,8 +34,6 @@ import java.util.Map;
 import java.util.TimeZone;
 
 import javax.el.FunctionMapper;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.transform.TransformerException;
 import javax.xml.transform.TransformerFactory;
 import javax.xml.transform.stream.StreamSource;
 
@@ -44,13 +41,11 @@ import org.apache.ofbiz.base.location.Fl
 import org.apache.ofbiz.base.util.Debug;
 import org.apache.ofbiz.base.util.FileUtil;
 import org.apache.ofbiz.base.util.UtilDateTime;
-import org.apache.ofbiz.base.util.UtilIO;
 import org.apache.ofbiz.base.util.UtilProperties;
 import org.apache.ofbiz.base.util.UtilXml;
 import org.cyberneko.html.parsers.DOMParser;
 import org.w3c.dom.Document;
 import org.w3c.dom.Node;
-import org.xml.sax.SAXException;
 
 /** Implements Unified Expression Language functions.
  * <p>Built-in functions are divided into a number of
@@ -266,7 +261,7 @@ public class UelFunctions {
                 this.functionMap.put("dom:toHtmlString", UelFunctions.class.getMethod("toHtmlString", Node.class, String.class, boolean.class, int.class));
                 this.functionMap.put("dom:toXmlString", UelFunctions.class.getMethod("toXmlString", Node.class, String.class, boolean.class, boolean.class, int.class));
                 this.functionMap.put("dom:writeXmlDocument", UelFunctions.class.getMethod("writeXmlDocument", String.class, Node.class, String.class, boolean.class, boolean.class, int.class));
-            } catch (NoSuchMethodException | NullPointerException | SecurityException e) {
+            } catch (Exception e) {
                 Debug.logError(e, "Error while initializing UelFunctions.Functions instance", module);
             }
             Debug.logVerbose("UelFunctions.Functions loaded " + this.functionMap.size() + " functions", module);
@@ -408,14 +403,14 @@ public class UelFunctions {
 
     public static String toLowerCase(String str) {
         try {
-            return str.toLowerCase(Locale.getDefault());
+            return str.toLowerCase();
         } catch (Exception e) {}
         return null;
     }
 
     public static String toUpperCase(String str) {
         try {
-            return str.toUpperCase(Locale.getDefault());
+            return str.toUpperCase();
         } catch (Exception e) {}
         return null;
     }
@@ -452,13 +447,11 @@ public class UelFunctions {
         try {
             URL url = FlexibleLocation.resolveLocation(str);
             if (url != null) {
-                try (InputStream is = url.openStream();) {
+                InputStream is = url.openStream();
                 result = true;
-                }
+                is.close();
             }
-        } catch (IOException e) {
-            Debug.log(e, module);
-        }
+        } catch (Exception e) {}
         return result;
     }
 
@@ -474,7 +467,7 @@ public class UelFunctions {
             } else {
                 Debug.logError("Unable to locate HTML document " + str, module);
             }
-        } catch (IOException | SAXException e) {
+        } catch (Exception e) {
             Debug.logError(e, "Error while reading HTML document " + str, module);
         }
         return document;
@@ -485,13 +478,13 @@ public class UelFunctions {
         try {
             URL url = FlexibleLocation.resolveLocation(str);
             if (url != null) {
-                try (InputStream is = url.openStream();) {
-                    document = UtilXml.readXmlDocument(is, str);
-                }
+                InputStream is = url.openStream();
+                document = UtilXml.readXmlDocument(is, str);
+                is.close();
             } else {
                 Debug.logError("Unable to locate XML document " + str, module);
             }
-        } catch (IOException | SAXException | ParserConfigurationException e) {
+        } catch (Exception e) {
             Debug.logError(e, "Error while reading XML document " + str, module);
         }
         return document;
@@ -501,14 +494,14 @@ public class UelFunctions {
         try {
             File file = FileUtil.getFile(str);
             if (file != null) {
-                try (FileOutputStream os = new FileOutputStream(file);) {
-                    UtilXml.writeXmlDocument(node, os, encoding, omitXmlDeclaration, indent, indentAmount);
-                    return true;
-                }
+                FileOutputStream os = new FileOutputStream(file);
+                UtilXml.writeXmlDocument(node, os, encoding, omitXmlDeclaration, indent, indentAmount);
+                os.close();
+                return true;
             } else {
                 Debug.logError("Unable to create XML document " + str, module);
             }
-        } catch (IOException | TransformerException | SecurityException e) {
+        } catch (Exception e) {
             Debug.logError(e, "Error while writing XML document " + str, module);
         }
         return false;
@@ -533,23 +526,25 @@ public class UelFunctions {
             sb.append("/>\n<xsl:template match=\"@*|node()\">\n");
             sb.append("<xsl:copy><xsl:apply-templates select=\"@*|node()\"/></xsl:copy>\n");
             sb.append("</xsl:template>\n</xsl:stylesheet>\n");
-            ByteArrayInputStream bis = new ByteArrayInputStream(sb.toString().getBytes(UtilIO.getUtf8()));
+            ByteArrayInputStream bis = new ByteArrayInputStream(sb.toString().getBytes());
             TransformerFactory transformerFactory = TransformerFactory.newInstance();
-            try (ByteArrayOutputStream os = new ByteArrayOutputStream();) {
-                UtilXml.transformDomDocument(transformerFactory.newTransformer(new StreamSource(bis)), node, os);
-                return os.toString();
-            }
-        } catch (IOException | TransformerException e) {
+            ByteArrayOutputStream os = new ByteArrayOutputStream();
+            UtilXml.transformDomDocument(transformerFactory.newTransformer(new StreamSource(bis)), node, os);
+            os.close();
+            return os.toString();
+        } catch (Exception e) {
             Debug.logError(e, "Error while creating HTML String ", module);
         }
         return null;
     }
 
     public static String toXmlString(Node node, String encoding, boolean omitXmlDeclaration, boolean indent, int indentAmount) {
-        try (ByteArrayOutputStream os = new ByteArrayOutputStream();) {
+        try {
+            ByteArrayOutputStream os = new ByteArrayOutputStream();
             UtilXml.writeXmlDocument(node, os, encoding, omitXmlDeclaration, indent, indentAmount);
+            os.close();
             return os.toString();
-        } catch (IOException | TransformerException e) {
+        } catch (Exception e) {
             Debug.logError(e, "Error while creating XML String ", module);
         }
         return null;

Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/string/UelUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/string/UelUtil.java?rev=1817963&r1=1817962&r2=1817963&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/string/UelUtil.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/string/UelUtil.java Tue Dec 12 22:32:00 2017
@@ -48,7 +48,7 @@ import org.apache.ofbiz.base.util.collec
 
 /** Implements the Unified Expression Language (JSR-245). */
 public final class UelUtil {
-    private static final String module = UelUtil.class.getName();
+    protected static final String module = UelUtil.class.getName();
     private static final String localizedMapLocaleKey = LocalizedMap.class.getName() + "_locale".replace(".", "_");
     private static final ExpressionFactory exprFactory = JuelConnector.newExpressionFactory();
     private static final ELResolver defaultResolver = new ExtendedCompositeResolver() {
@@ -61,13 +61,13 @@ public final class UelUtil {
             add(new BeanELResolver(false));
         }
     };
-
+    
     private UelUtil () {}
-
+    
     public static String getLocalizedMapLocaleKey() {
         return localizedMapLocaleKey;
     }
-
+    
     /** Evaluates a Unified Expression Language expression and returns the result.
      * @param context Evaluation context (variables)
      * @param expression UEL expression
@@ -242,9 +242,6 @@ public final class UelUtil {
 
         @Override
         public boolean equals(Object obj) {
-            if (obj == null) {
-                return false;
-            }
             if (this == obj) {
                 return true;
             }
@@ -271,7 +268,7 @@ public final class UelUtil {
         public boolean isLiteralText() {
             return false;
         }
-
+        
     }
 
     @SuppressWarnings("serial")
@@ -284,9 +281,6 @@ public final class UelUtil {
         }
         @Override
         public boolean equals(Object obj) {
-            if (obj == null) {
-                return false;
-            }
             if (this == obj) {
                 return true;
             }
@@ -344,7 +338,7 @@ public final class UelUtil {
         @Override
         public void setValue(ELContext context, Object base, Object property, Object val) {
             super.setValue(context, base, property, val);
-            if (!context.isPropertyResolved() && base != null) {
+            if (!context.isPropertyResolved() && base == null) {
                 if (Debug.verboseOn()) {
                     Debug.logVerbose("ExtendedCompositeResolver.setValue: base = " + base + ", property = " + property + ", value = " + val, module);
                 }