lundi 5 juin 2023

Field.class.getDeclaredFields() is returning an empty array [duplicate]

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.





Aucun commentaire:

Enregistrer un commentaire