Improved: Fixing defects reported by FindBugs, package
org.apache.ofbiz.base.conversion. (OFBIZ-9679) Thanks Dennis Balkir for reporting and providing the patch. git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1811434 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
+2
-1
@@ -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 implements ConverterLoader {
|
||||
}
|
||||
|
||||
public Boolean convert(String obj) throws ConversionException {
|
||||
return "TRUE".equals(obj.trim().toUpperCase());
|
||||
return "TRUE".equals(obj.trim().toUpperCase(Locale.getDefault()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+5
-5
@@ -43,10 +43,10 @@ public class CollectionConverters implements ConverterLoader {
|
||||
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 implements ConverterLoader {
|
||||
}
|
||||
|
||||
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 implements ConverterLoader {
|
||||
}
|
||||
|
||||
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 implements ConverterLoader {
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -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.UtilGenerics;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -169,10 +169,9 @@ public class MiscConverters implements ConverterLoader {
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user