mardi 28 mai 2019

Unable to use java.lang.reflect.Field.modifiers in Java 11

Recently passed from Java 9 to Java 11 where the code below used to work fine :

        final Field a = bb.class.getDeclaredField("a");
        a.setAccessible(true);
        final Field b = bb.class.getDeclaredField("b");
        b.setAccessible(true);
        final Field modifersField = Field.class.getDeclaredField("modifiers");
        modifersField.setAccessible(true);
        modifersField.setInt(a, ~Modifier.FINAL & a.getModifiers());
        modifersField.setInt(b, ~Modifier.FINAL & b.getModifiers());
        a.set(null, BigInteger.valueOf(5));
        b.set(null, BigInteger.valueOf(5));
        modifersField.setAccessible(false);

But in Java 11 i get this error :

java.lang.reflect.InaccessibleObjectException: Unable to make field private int java.lang.reflect.Field.modifiers accessible: module java.base does not "opens java.lang.reflect" to module 

I tried added VM Parameters like :

--add-exports
javafx.base/java.lang.reflect=com.goxr3plus.applicationName

But again nothing ... just a warning and application crashes :

WARNING: package java.lang.reflect not in javafx.base

What am i doing wrong ?





Aucun commentaire:

Enregistrer un commentaire