From bf21151856bcc9851ffae910f47fb723543988d3 Mon Sep 17 00:00:00 2001 From: Marc Baloup Date: Wed, 22 Jun 2022 00:19:22 +0200 Subject: [PATCH] Trying better ReflectRegistry initialization --- .../pandacube/lib/paper/reflect/ReflectRegistry.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Paper/src/main/java/fr/pandacube/lib/paper/reflect/ReflectRegistry.java b/Paper/src/main/java/fr/pandacube/lib/paper/reflect/ReflectRegistry.java index 3862cd5..6bda05b 100644 --- a/Paper/src/main/java/fr/pandacube/lib/paper/reflect/ReflectRegistry.java +++ b/Paper/src/main/java/fr/pandacube/lib/paper/reflect/ReflectRegistry.java @@ -3,6 +3,8 @@ package fr.pandacube.lib.paper.reflect; import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx; import java.io.File; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; import java.util.List; import java.util.UUID; @@ -474,14 +476,18 @@ public class ReflectRegistry { private static void initRecursively(Class cl) { try { - Class.forName(cl.getName()); // force initializing the member classes + Log.info("Init reflect registry class " + cl + "..."); + for (Field f : Reflect.ofClass(cl).get().getDeclaredFields()) { + if (Modifier.isStatic(f.getModifiers())) + f.get(null); + } } catch (ExceptionInInitializerError e) { Log.severe("Error while initilizing a ReflectRegistry entry at " + cl.getName(), e.getCause()); } catch (NoClassDefFoundError e) { // if a previously initialized class failed to actually initialize Log.severe("Error while initilizing a ReflectRegistry entry at " + cl.getName() + " due to a previously failed initialization (" + e.getMessage() + ")"); - } catch (ClassNotFoundException e) { - Log.severe("Wut? (should not append)", e); + } catch (Throwable t) { + Log.severe("Wut?", t); } for (Class declaredClass : cl.getDeclaredClasses()) { initRecursively(declaredClass);