0

When trying to get the modifiers field from the Field class reflectively, I get a NoSuchFieldException. And when printing out a list of the declared fields I get an empty array.

 try {
        modifiersField = Field.class.getDeclaredField("modifiers");
        modifiersField.setAccessible(true);
 } catch (NoSuchFieldException e) {
        throw new RuntimeException(e + Arrays.toString(Arrays.stream(Field.class.getDeclaredFields()).map(Field::getName).toArray()));
 }

Output: java.lang.RuntimeException: java.lang.NoSuchFieldException: modifiers[]

Tried updating Java, Tried doing it in Kotlin. To no avail.

maxy
  • 5
  • 3
  • 2
    If you need the value of the `modifiers` field, use its public accessor: `getModifiers()`. If you want to change the modifiers, use a java agent to change the bytecode before it is loaded. – Johannes Kuhn Jun 05 '23 at 21:48

0 Answers0