DATACMNS-601 - Fixes for most of the SonarQube warnings.
This commit is contained in:
@@ -55,7 +55,7 @@ public enum BytecodeGeneratingEntityInstantiator implements EntityInstantiator {
|
||||
|
||||
INSTANCE;
|
||||
|
||||
private final ObjectInstantiatorClassGenerator classGenerator = ObjectInstantiatorClassGenerator.INSTANCE;
|
||||
private static final ObjectInstantiatorClassGenerator GENERATOR = ObjectInstantiatorClassGenerator.INSTANCE;
|
||||
|
||||
private volatile Map<TypeInformation<?>, EntityInstantiator> entityInstantiators = new HashMap<TypeInformation<?>, EntityInstantiator>(
|
||||
32);
|
||||
@@ -149,47 +149,14 @@ public enum BytecodeGeneratingEntityInstantiator implements EntityInstantiator {
|
||||
* @return
|
||||
*/
|
||||
private ObjectInstantiator createObjectInstantiator(PersistentEntity<?, ?> entity) {
|
||||
|
||||
try {
|
||||
return (ObjectInstantiator) classGenerator.generateCustomInstantiatorClass(entity).newInstance();
|
||||
} catch (Throwable e) {
|
||||
return (ObjectInstantiator) GENERATOR.generateCustomInstantiatorClass(entity).newInstance();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A {@link ClassLoader} that can load classes from {@code byte[]} representations.
|
||||
*
|
||||
* @author Thomas Darimont
|
||||
*/
|
||||
private static class ByteArrayClassLoader extends ClassLoader {
|
||||
|
||||
public ByteArrayClassLoader(ClassLoader parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to load a class given {@code byte[]}.
|
||||
*
|
||||
* @param name must not be {@literal null}
|
||||
* @param bytes must not be {@literal null}
|
||||
* @return
|
||||
*/
|
||||
public Class<?> loadClass(String name, byte[] bytes) {
|
||||
|
||||
Assert.notNull(name, "name must not be null");
|
||||
Assert.notNull(bytes, "bytes must not be null");
|
||||
|
||||
try {
|
||||
Class<?> clazz = findClass(name);
|
||||
if (clazz != null) {
|
||||
return clazz;
|
||||
}
|
||||
} catch (ClassNotFoundException ignore) {}
|
||||
|
||||
return defineClass(name, bytes, 0, bytes.length);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adapter to forward an invocation of the {@link EntityInstantiator} API to an {@link ObjectInstantiator}.
|
||||
*
|
||||
@@ -256,7 +223,7 @@ public enum BytecodeGeneratingEntityInstantiator implements EntityInstantiator {
|
||||
/**
|
||||
* @author Thomas Darimont
|
||||
*/
|
||||
public static interface ObjectInstantiator {
|
||||
interface ObjectInstantiator {
|
||||
|
||||
Object newInstance(Object... args);
|
||||
}
|
||||
@@ -495,5 +462,39 @@ public enum BytecodeGeneratingEntityInstantiator implements EntityInstantiator {
|
||||
throw new IllegalArgumentException("Unboxing should not be attempted for descriptor '" + ch + "'");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A {@link ClassLoader} that can load classes from {@code byte[]} representations.
|
||||
*
|
||||
* @author Thomas Darimont
|
||||
*/
|
||||
private class ByteArrayClassLoader extends ClassLoader {
|
||||
|
||||
public ByteArrayClassLoader(ClassLoader parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to load a class given {@code byte[]}.
|
||||
*
|
||||
* @param name must not be {@literal null}
|
||||
* @param bytes must not be {@literal null}
|
||||
* @return
|
||||
*/
|
||||
public Class<?> loadClass(String name, byte[] bytes) {
|
||||
|
||||
Assert.notNull(name, "name must not be null");
|
||||
Assert.notNull(bytes, "bytes must not be null");
|
||||
|
||||
try {
|
||||
Class<?> clazz = findClass(name);
|
||||
if (clazz != null) {
|
||||
return clazz;
|
||||
}
|
||||
} catch (ClassNotFoundException ignore) {}
|
||||
|
||||
return defineClass(name, bytes, 0, bytes.length);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.springframework.util.Assert;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class CollectionFactory {
|
||||
public abstract class CollectionFactory {
|
||||
|
||||
private CollectionFactory() {}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ import org.springframework.util.StringUtils;
|
||||
public class SimpleTypeInformationMapper implements TypeInformationMapper {
|
||||
|
||||
public static final SimpleTypeInformationMapper INSTANCE = new SimpleTypeInformationMapper();
|
||||
private static final Map<String, ClassTypeInformation<?>> cache = new ConcurrentHashMap<String, ClassTypeInformation<?>>();
|
||||
private static final Map<String, ClassTypeInformation<?>> CACHE = new ConcurrentHashMap<String, ClassTypeInformation<?>>();
|
||||
|
||||
/**
|
||||
* Returns the {@link TypeInformation} that shall be used when the given {@link String} value is found as type hint.
|
||||
@@ -56,7 +56,7 @@ public class SimpleTypeInformationMapper implements TypeInformationMapper {
|
||||
return null;
|
||||
}
|
||||
|
||||
ClassTypeInformation<?> information = cache.get(value);
|
||||
ClassTypeInformation<?> information = CACHE.get(value);
|
||||
|
||||
if (information != null) {
|
||||
return information;
|
||||
@@ -69,7 +69,7 @@ public class SimpleTypeInformationMapper implements TypeInformationMapper {
|
||||
}
|
||||
|
||||
if (information != null) {
|
||||
cache.put(value, information);
|
||||
CACHE.put(value, information);
|
||||
}
|
||||
|
||||
return information;
|
||||
|
||||
Reference in New Issue
Block a user