Trying better ReflectRegistry initialization

This commit is contained in:
Marc Baloup 2022-06-22 00:19:22 +02:00
parent e21b2ffe67
commit bf21151856
Signed by: marcbal
GPG Key ID: BBC0FE3ABC30B893
1 changed files with 9 additions and 3 deletions

View File

@ -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);