Skip to content

Commit e239171

Browse files
committed
Some more reflection fixes
1 parent b1863f3 commit e239171

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

src/main/java/com/falsepattern/lib/internal/ReflectionUtil.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,37 @@ public class ReflectionUtil {
3131

3232
static {
3333
try {
34-
f_modifiers = Field.class.getDeclaredField("modifiers");
34+
f_modifiers = getModifiersField();
3535
} catch (NoSuchFieldException e) {
3636
throw new RuntimeException(e);
3737
}
3838
f_modifiers.setAccessible(true);
3939
}
4040

41+
// ref: https://github.com/prestodb/presto/pull/15240/files#diff-8bf996e5c1d4fb088b84ae0528bc42686b0724bcf5a2692a1e7b5eff32c90cce
42+
private static Field getModifiersField() throws NoSuchFieldException
43+
{
44+
try {
45+
return Field.class.getDeclaredField("modifiers");
46+
}
47+
catch (NoSuchFieldException e) {
48+
try {
49+
Method getDeclaredFields0 = Class.class.getDeclaredMethod("getDeclaredFields0", boolean.class);
50+
getDeclaredFields0.setAccessible(true);
51+
Field[] fields = (Field[]) getDeclaredFields0.invoke(Field.class, false);
52+
for (Field field : fields) {
53+
if ("modifiers".equals(field.getName())) {
54+
return field;
55+
}
56+
}
57+
}
58+
catch (ReflectiveOperationException ex) {
59+
e.addSuppressed(ex);
60+
}
61+
throw e;
62+
}
63+
}
64+
4165
@SneakyThrows
4266
public static void jailBreak(Field field) {
4367
field.setAccessible(true);

0 commit comments

Comments
 (0)