jaxb-ri icon indicating copy to clipboard operation
jaxb-ri copied to clipboard

Unable to make field private ... accessible: module ... does not "opens ..." to module com.sun.xml.bind

Open mkarg opened this issue 1 year ago • 2 comments

While I am using Java SE / EE for decades, I need to confess that I am a newbie with Java Modules. Kindly begging for help!

I have written some JAXB elements in Java and want to package them as a Java Module using the following module-info declaration:

...
opens ... to jakarta.xml.bind, com.sun.xml.bind;
...

That is working pretty well. I can even remove the to part and it still works. 😄

But what I actually want to write is this, as any JAXB implementation shall be able to reflect (but not anybody):

...
opens ... to jakarta.xml.bind;
...

Unfortunately, what happens is this:

java.lang.reflect.InaccessibleObjectException: Unable to make field private ... accessible: module ... does not "opens ..." to module com.sun.xml.bind
        at java.base/java.lang.reflect.AccessibleObject.throwInaccessibleObjectException(AccessibleObject.java:387)
        at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:363)
        at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:311)
        at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:180)
        at java.base/java.lang.reflect.Field.setAccessible(Field.java:174)
        at [email protected]/org.glassfish.jaxb.runtime.v2.runtime.reflect.Accessor$FieldReflection.<init>(Accessor.java:213)

What am I doing wrong?

mkarg avatar Oct 07 '24 14:10 mkarg