Add support for OpenJ9 13

Dieser Commit ist enthalten in:
mathiascode 2020-02-22 05:53:25 +02:00
Ursprung 3a050fba3b
Commit 4095786bbe

Datei anzeigen

@ -1,5 +1,6 @@
package com.boydti.fawe.util; package com.boydti.fawe.util;
import java.lang.invoke.MethodHandles;
import java.lang.reflect.AccessibleObject; import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.Field; import java.lang.reflect.Field;
@ -32,26 +33,15 @@ public class ReflectionUtils {
// letting us modify the static final field // letting us modify the static final field
if (Modifier.isFinal(field.getModifiers())) { if (Modifier.isFinal(field.getModifiers())) {
try { try {
Field modifiersField = Field.class.getDeclaredField("modifiers"); Field lookupField = MethodHandles.Lookup.class.getDeclaredField("IMPL_LOOKUP");
modifiersField.setAccessible(true); lookupField.setAccessible(true);
int modifiers = modifiersField.getInt(field);
// blank out the final bit in the modifiers int // blank out the final bit in the modifiers int
modifiers &= ~Modifier.FINAL; ((MethodHandles.Lookup) lookupField.get(null))
modifiersField.setInt(field, modifiers); .findSetter(Field.class, "modifiers", int.class)
} catch (NoSuchFieldException e) { .invokeExact(field, field.getModifiers() & ~Modifier.FINAL);
// Java 12+ compatibility - search fields with hidden method for modifiers } catch (Throwable e) {
// same concept as above, just with a more hacky way of getting to the modifiers e.printStackTrace();
Method getDeclaredFields0 = Class.class.getDeclaredMethod("getDeclaredFields0", boolean.class);
getDeclaredFields0.setAccessible(true);
Field[] fields = (Field[]) getDeclaredFields0.invoke(Field.class, false);
for (Field classField : fields) {
if ("modifiers".equals(classField.getName())) {
classField.setAccessible(true);
classField.set(field, field.getModifiers() & ~Modifier.FINAL);
break;
}
}
} }
} }
} }