Skip to content

Commit

Permalink
Add workaround for constructor cache bug (#13679)
Browse files Browse the repository at this point in the history
Workaround for #13509
  • Loading branch information
viliam-durina committed Sep 3, 2018
1 parent 72b1e0e commit ce11380
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions hazelcast/src/main/java/com/hazelcast/nio/ClassLoaderUtil.java
Expand Up @@ -44,6 +44,8 @@ public final class ClassLoaderUtil {
public static final String HAZELCAST_ARRAY = "[L" + HAZELCAST_BASE_PACKAGE;

private static final boolean CLASS_CACHE_DISABLED = Boolean.getBoolean("hazelcast.compat.classloading.cache.disabled");
private static final boolean CONSTRUCTOR_CACHE_DISABLED =
Boolean.getBoolean("hazelcast.classloading.constructor.cache.disabled");

private static final Map<String, Class> PRIMITIVE_CLASSES;
private static final int MAX_PRIM_CLASSNAME_LENGTH = 7;
Expand Down Expand Up @@ -94,9 +96,11 @@ public static <T> T getOrCreate(T instance, ClassLoader classLoader, String clas
@SuppressWarnings("unchecked")
public static <T> T newInstance(ClassLoader classLoader, final String className) throws Exception {
classLoader = classLoader == null ? ClassLoaderUtil.class.getClassLoader() : classLoader;
Constructor<T> constructor = CONSTRUCTOR_CACHE.get(classLoader, className);
if (constructor != null) {
return constructor.newInstance();
if (!CONSTRUCTOR_CACHE_DISABLED) {
Constructor<T> constructor = CONSTRUCTOR_CACHE.get(classLoader, className);
if (constructor != null) {
return constructor.newInstance();
}
}
Class<T> klass = (Class<T>) loadClass(classLoader, className);
return newInstance(klass, classLoader, className);
Expand All @@ -107,7 +111,7 @@ public static <T> T newInstance(Class<T> klass, ClassLoader classLoader, String
if (!constructor.isAccessible()) {
constructor.setAccessible(true);
}
if (!shouldBypassCache(klass)) {
if (!shouldBypassCache(klass) && !CONSTRUCTOR_CACHE_DISABLED) {
CONSTRUCTOR_CACHE.put(classLoader, className, constructor);
}
return constructor.newInstance();
Expand Down

0 comments on commit ce11380

Please sign in to comment.