mirror of
https://github.com/FalsePattern/FalsePatternLib.git
synced 2026-11-11 14:57:30 +00:00
Some more reflection fixes
This commit is contained in:
1 file changed
+25
-1
@@ -31,13 +31,37 @@ public class ReflectionUtil {
|
||||
|
||||
static {
|
||||
try {
|
||||
f_modifiers = Field.class.getDeclaredField("modifiers");
|
||||
f_modifiers = getModifiersField();
|
||||
} catch (NoSuchFieldException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
f_modifiers.setAccessible(true);
|
||||
}
|
||||
|
||||
// ref: https://github.com/prestodb/presto/pull/15240/files#diff-8bf996e5c1d4fb088b84ae0528bc42686b0724bcf5a2692a1e7b5eff32c90cce
|
||||
private static Field getModifiersField() throws NoSuchFieldException
|
||||
{
|
||||
try {
|
||||
return Field.class.getDeclaredField("modifiers");
|
||||
}
|
||||
catch (NoSuchFieldException e) {
|
||||
try {
|
||||
Method getDeclaredFields0 = Class.class.getDeclaredMethod("getDeclaredFields0", boolean.class);
|
||||
getDeclaredFields0.setAccessible(true);
|
||||
Field[] fields = (Field[]) getDeclaredFields0.invoke(Field.class, false);
|
||||
for (Field field : fields) {
|
||||
if ("modifiers".equals(field.getName())) {
|
||||
return field;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (ReflectiveOperationException ex) {
|
||||
e.addSuppressed(ex);
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public static void jailBreak(Field field) {
|
||||
field.setAccessible(true);
|
||||
|
||||
Reference in new issue
Block a user