highsource / jaxb2-basics

Useful plugins and tools for JAXB2.
BSD 2-Clause "Simplified" License
108 stars 54 forks source link

InaccessibleObjectException #130

Closed brookman closed 1 year ago

brookman commented 2 years ago

After updating to JDK 17 I am getting the following exception:

java.lang.reflect.InaccessibleObjectException: Unable to make public java.lang.Object com.sun.org.apache.xerces.internal.jaxp.datatype.XMLGregorianCalendarImpl.clone() accessible: module java.xml does not "exports com.sun.org.apache.xerces.internal.jaxp.datatype" to unnamed module @3d34d211

The DefaultCopyStrategy tries to set method.setAccessible(true) (on line 249) which fails. In this case it tries to set XMLGregorianCalendarImpl.clone() to accessible which is in fact public but for some reason method.isAccessible() returns false.

Boris-de commented 1 year ago

In this case it tries to set XMLGregorianCalendarImpl.clone() to accessible which is in fact public but for some reason method.isAccessible() returns false.

The problem is that the XMLGregorianCalendarImpl class as a whole is not accessible because it is in a module that does not export (or opens) this class specificly. Without using reflection this is not a problem because you would never call methods from XMLGregorianCalendarImpl anyway, because you would use XMLGregorianCalendar and only methods from that. The v-table-lookup (I think) will then dispatch the call to XMLGregorianCalendar.clone() to XMLGregorianCalendarImpl.clone()

My PR #163 would fix this by using the first accessible clone method in the class hierarchy.

laurentschoelens commented 1 year ago

@brookman the fix provided by @Boris-de isn't merged yet but I provided similar fix in my PR of merging this repo in main jaxb-tools repository which will be the main repo for maven plugin / basics / annotate repositories

Also thanks to @Boris-de for providing initial fix proposal for this issue

laurentschoelens commented 1 year ago

See changes in DefaultCopyStrategy in commit https://github.com/highsource/jaxb-tools/commit/567d22ab7686b886ae21be24c76ee58bacb50cc1