jdk 9 reflection problem using TreeMapConverter

3,630 views
Skip to first unread message

Michael Musgrove

unread,
Jan 6, 2017, 1:51:17 PM1/6/17
to XStream User
TreeMapConverter is used by the maven war plugin and is causing an issue on recent jdk 9 builds because it is trying to change the accessibility of one of the fields of TreeMap. The comparator() method could be used instead of accessing the field directly.

I posted the question on the wildfly dev list (http://lists.jboss.org/pipermail/wildfly-dev/2017-January/005653.html) but I am posting here too since it would be good to get it fixed in XStream because the workaround is unpleasant (I have to add the --add-opens jdk 9 flag to MAVEN_OPTS to force the war plugin and XStream to allow the access to the private field which affects all maven modules in a build).

The following is a copy from my wildfly dev post of the error:

[WARNING] Error injecting: org.apache.maven.plugins.war.WarMojo
com.google.inject.ProvisionException: Unable to provision, see the following errors:

1) Error injecting constructor, java.lang.ExceptionInInitializerError
at org.apache.maven.plugins.war.WarMojo.<init>(Unknown Source)
while locating org.apache.maven.plugins.war.WarMojo

...

Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make field private final java.util.Comparator java.util.TreeMap.comparator accessible: module java.base does not "opens java.util" to unnamed m
odule @669f2128
at java.base/jdk.internal.reflect.Reflection.throwInaccessibleObjectException(Reflection.java:427)
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:201)
at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:171)
at java.base/java.lang.reflect.Field.setAccessible(Field.java:165)
at com.thoughtworks.xstream.core.util.Fields.locate(Fields.java:40)
at com.thoughtworks.xstream.converters.collections.TreeMapConverter.<clinit>(TreeMapConverter.java:50)

Jörg Schaible

unread,
Jan 6, 2017, 7:03:06 PM1/6/17
to xstrea...@googlegroups.com
Hi Michael,

Michael Musgrove wrote:

> TreeMapConverter is used by the maven war plugin and is causing an issue
> on recent jdk 9 builds because it is trying to change the accessibility of
> one of the fields of TreeMap.

There are a lot more issues with Java 9.

> The comparator() method could be used
> instead of accessing the field directly.

No it cannot. XStream has to recreate the TreeMap without calling the
element's compare method, because it would have other unpleasant side-
effects including security issues. This is currently not possible without
accessing the field via reflection.

Java 9 in it's current form and XStream are currently not compatible.
However, the complete module stuff is still a target of ongoing changes.

Cheers,
Jörg

liux...@gmail.com

unread,
Jan 12, 2017, 10:32:13 PM1/12/17
to XStream User, joerg.s...@gmx.de
Hi Joehni,
there is one issue about the compatibility. I just wondering when a new version will come out and erase these issues about compatibility with jdk9

[testlogic] java.lang.reflect.InaccessibleObjectException: Unable to make
field private java.lang.String
java.text.AttributedCharacterIterator$Attribute.name accessible: module
java.base does not "opens java.text" to unnamed module @799c3a63
[testlogic] at
java.base/jdk.internal.reflect.Reflection.throwInaccessibleObjectException(Ref
lection.java:424)
[testlogic] at
java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleO
bject.java:198)
[testlogic] at
java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:171)
[testlogic] at
java.base/java.lang.reflect.Field.setAccessible(Field.java:165)
[testlogic] at
com.thoughtworks.xstream.converters.reflection.FieldDictionary.buildMap(FieldD
ictionary.java:129)
[testlogic] at
com.thoughtworks.xstream.converters.reflection.FieldDictionary.fieldsFor(Field
Dictionary.java:75)
[testlogic] at
com.thoughtworks.xstream.converters.reflection.AbstractAttributedCharacterIter
atorAttributeConverter.readResolve(AbstractAttributedCharacterIteratorAttribut
eConverter.java:83)
[testlogic] at
com.thoughtworks.xstream.converters.reflection.AbstractAttributedCharacterIter
atorAttributeConverter.<init>(AbstractAttributedCharacterIteratorAttributeConv
erter.java:52)
[testlogic] at
com.thoughtworks.xstream.converters.extended.TextAttributeConverter.<init>(Tex
tAttributeConverter.java:33)
[testlogic] at
com.thoughtworks.xstream.XStream.setupConverters(XStream.java:662)
[testlogic] at com.thoughtworks.xstream.XStream.<init>(XStream.java:445)
[testlogic] at com.thoughtworks.xstream.XStream.<init>(XStream.java:385)
[testlogic] at com.thoughtworks.xstream.XStream.<init>(XStream.java:323)
[testlogic] at
org.testlogic.testrunner.ant.cactus.utils.CactusRemoteHelper.setRemoteProperti
es(CactusRemoteHelper.java:53)
Reply all
Reply to author
Forward
0 new messages