From 2a6654746edb073c26e95b3c055e5e998b3dde4e Mon Sep 17 00:00:00 2001 From: Marc Baloup Date: Mon, 27 Dec 2021 23:56:21 +0100 Subject: [PATCH] Initialize fieldCache and methodCache before unsafe instance in ReflectionUtil --- .../pandacube/lib/core/util/ReflectionUtil.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/Core/src/main/java/fr/pandacube/lib/core/util/ReflectionUtil.java b/Core/src/main/java/fr/pandacube/lib/core/util/ReflectionUtil.java index 78868ef..63128ea 100644 --- a/Core/src/main/java/fr/pandacube/lib/core/util/ReflectionUtil.java +++ b/Core/src/main/java/fr/pandacube/lib/core/util/ReflectionUtil.java @@ -22,16 +22,25 @@ import io.github.classgraph.ScanResult; import sun.misc.Unsafe; public class ReflectionUtil { + + private record MethodCacheKey(Class clazz, String methodName, List> parameters) { } + private static final Map methodCache; + + private record FieldCacheKey(Class clazz, String fieldName) { }; + private static final Map fieldCache; + private static final Unsafe sunMiscUnsafeInstance; static { + methodCache = new HashMap<>(); + fieldCache = new HashMap<>(); try { sunMiscUnsafeInstance = (Unsafe) field("theUnsafe") .inClass(Unsafe.class) .getStaticValue(); } catch (Exception e) { - throw new RuntimeException(e); + throw new RuntimeException("Cannot access to " + Unsafe.class + ".theUnsafe value.", e); } } @@ -40,12 +49,6 @@ public class ReflectionUtil { - private record MethodCacheKey(Class clazz, String methodName, List> parameters) { } - private static final Map methodCache = new HashMap<>(); - - private record FieldCacheKey(Class clazz, String fieldName) { }; - private static final Map fieldCache = new HashMap<>(); -