svn commit: r1811434 - in /ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/conversion: BooleanConverters.java CollectionConverters.java Converters.java MiscConverters.java

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

svn commit: r1811434 - in /ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/conversion: BooleanConverters.java CollectionConverters.java Converters.java MiscConverters.java

mbrohl
Author: mbrohl
Date: Sat Oct  7 14:53:43 2017
New Revision: 1811434

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

Thanks Dennis Balkir for reporting and providing the patch.

Modified:
    ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/conversion/BooleanConverters.java
    ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/conversion/CollectionConverters.java
    ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/conversion/Converters.java
    ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/conversion/MiscConverters.java

Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/conversion/BooleanConverters.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/conversion/BooleanConverters.java?rev=1811434&r1=1811433&r2=1811434&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/conversion/BooleanConverters.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/conversion/BooleanConverters.java Sat Oct  7 14:53:43 2017
@@ -18,6 +18,7 @@
  *******************************************************************************/
 package org.apache.ofbiz.base.conversion;
 
+import java.util.Locale;
 
 /** Boolean Converter classes. */
 public class BooleanConverters implements ConverterLoader {
@@ -69,7 +70,7 @@ public class BooleanConverters implement
         }
 
         public Boolean convert(String obj) throws ConversionException {
-            return "TRUE".equals(obj.trim().toUpperCase());
+            return "TRUE".equals(obj.trim().toUpperCase(Locale.getDefault()));
         }
     }
 

Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/conversion/CollectionConverters.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/conversion/CollectionConverters.java?rev=1811434&r1=1811433&r2=1811434&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/conversion/CollectionConverters.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/conversion/CollectionConverters.java Sat Oct  7 14:53:43 2017
@@ -43,10 +43,10 @@ public class CollectionConverters implem
             if (targetClass != List.class) {
                return null;
             }
-            if (!(sourceClass.getComponentType() instanceof Object)) {
+            if (sourceClass.getComponentType() == null) {
                 return null;
             }
-            return UtilGenerics.cast(new ArrayClassToList<S, T>(sourceClass, targetClass));
+            return UtilGenerics.cast(new ArrayClassToList<>(sourceClass, targetClass));
         }
     }
 
@@ -61,7 +61,7 @@ public class CollectionConverters implem
         }
 
         public T convert(S obj) throws ConversionException {
-            List<Object> list = new LinkedList<Object>();
+            List<Object> list = new LinkedList<>();
             int len = Array.getLength(obj);
             for (int i = 0; i < len; i++) {
                 list.add(Array.get(obj, i));
@@ -110,7 +110,7 @@ public class CollectionConverters implem
         }
 
         public List<Map<K, V>> convert(Map<K, V> obj) throws ConversionException {
-            List<Map<K, V>> tempList = new LinkedList<Map<K, V>>();
+            List<Map<K, V>> tempList = new LinkedList<>();
             tempList.add(obj);
             return tempList;
         }
@@ -122,7 +122,7 @@ public class CollectionConverters implem
         }
 
         public Set<Map<K, V>> convert(Map<K, V> obj) throws ConversionException {
-            Set<Map<K, V>> tempSet = new HashSet<Map<K, V>>();
+            Set<Map<K, V>> tempSet = new HashSet<>();
             tempSet.add(obj);
             return tempSet;
         }

Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/conversion/Converters.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/conversion/Converters.java?rev=1811434&r1=1811433&r2=1811434&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/conversion/Converters.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/conversion/Converters.java Sat Oct  7 14:53:43 2017
@@ -18,6 +18,7 @@
  *******************************************************************************/
 package org.apache.ofbiz.base.conversion;
 
+import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Modifier;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -35,9 +36,9 @@ import org.apache.ofbiz.base.util.UtilGe
 public class Converters {
     protected static final String module = Converters.class.getName();
     protected static final String DELIMITER = "->";
-    protected static final ConcurrentHashMap<String, Converter<?, ?>> converterMap = new ConcurrentHashMap<String, Converter<?, ?>>();
-    protected static final Set<ConverterCreator> creators = new HashSet<ConverterCreator>();
-    protected static final Set<String> noConversions = new HashSet<String>();
+    protected static final ConcurrentHashMap<String, Converter<?, ?>> converterMap = new ConcurrentHashMap<>();
+    private static final Set<ConverterCreator> creators = new HashSet<>();
+    private static final Set<String> noConversions = new HashSet<>();
 
     static {
         registerCreator(new PassThruConverterCreator());
@@ -151,7 +152,7 @@ OUTER:
                         loader.loadConverters();
                     }
                 }
-            } catch (Exception e) {
+            } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
                 Debug.logError(e, module);
             }
         }
@@ -204,10 +205,9 @@ OUTER:
 
         public <S, T> Converter<S, T> createConverter(Class<S> sourceClass, Class<T> targetClass) {
             if (ObjectType.instanceOf(sourceClass, targetClass)) {
-                return new PassThruConverter<S, T>(sourceClass, targetClass);
-            } else {
-                return null;
+                return new PassThruConverter<>(sourceClass, targetClass);
             }
+            return null;
         }
     }
 

Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/conversion/MiscConverters.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/conversion/MiscConverters.java?rev=1811434&r1=1811433&r2=1811434&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/conversion/MiscConverters.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/conversion/MiscConverters.java Sat Oct  7 14:53:43 2017
@@ -169,10 +169,9 @@ public class MiscConverters implements C
 
         public <S, T> Converter<S, T> createConverter(Class<S> sourceClass, Class<T> targetClass) {
             if (String.class == sourceClass && Enum.class.isAssignableFrom(targetClass)) {
-                return UtilGenerics.cast(new StringToEnum<E>());
-            } else {
-                return null;
+                return UtilGenerics.cast(new StringToEnum<>());
             }
+            return null;
         }
     }