Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fails on Java 16 for java.util.Arrays$ArrayList and java.util.Collections$EmptyList #253

Closed
famod opened this issue May 9, 2021 · 14 comments
Assignees
Labels

Comments

@famod
Copy link
Contributor

famod commented May 9, 2021

Over at Quarkus (see also quarkusio/quarkus#17091), I had to disable two test classes for the JDK 16 CI job due to:

Conversions fails for Arrays.asList(...):

com.thoughtworks.xstream.converters.ConversionException:
No converter available
---- Debugging information ----
message             : No converter available
type                : java.util.Arrays$ArrayList
converter           : com.thoughtworks.xstream.converters.reflection.ReflectionConverter
message[1]          : Unable to make field protected transient int java.util.AbstractList.modCount accessible: module java.base does not "opens java.util" to unnamed module @2a79781f
-------------------------------
        at com.thoughtworks.xstream.core.DefaultConverterLookup.lookupConverterForType(DefaultConverterLookup.java:78)
        at com.thoughtworks.xstream.XStream$1.lookupConverterForType(XStream.java:543)
        at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:50)
        at com.thoughtworks.xstream.core.AbstractReferenceMarshaller$1.convertAnother(AbstractReferenceMarshaller.java:88)
        at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshallField(AbstractReflectionConverter.java:269)
        at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.writeField(AbstractReflectionConverter.java:173)
        at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doMarshal(AbstractReflectionConverter.java:262)
        at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshal(AbstractReflectionConverter.java:92)
        at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:69)
        at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:59)
        at com.thoughtworks.xstream.core.AbstractReferenceMarshaller$1.convertAnother(AbstractReferenceMarshaller.java:88)
        at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshallField(AbstractReflectionConverter.java:269)
        at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.writeField(AbstractReflectionConverter.java:173)
        at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doMarshal(AbstractReflectionConverter.java:262)
        at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshal(AbstractReflectionConverter.java:92)
        at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:69)
        at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:59)
        at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:44)
        at com.thoughtworks.xstream.core.TreeMarshaller.start(TreeMarshaller.java:81)
        at com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.marshal(AbstractTreeMarshallingStrategy.java:41)
        at com.thoughtworks.xstream.XStream.marshal(XStream.java:1198)
        at com.thoughtworks.xstream.XStream.marshal(XStream.java:1187)
        at com.thoughtworks.xstream.XStream.toXML(XStream.java:1159)
        at com.thoughtworks.xstream.XStream.toXML(XStream.java:1145)

Conversions fails for Collections.emptyList():

com.thoughtworks.xstream.converters.ConversionException:
No converter available
---- Debugging information ----
message             : No converter available
type                : java.util.Collections$EmptyList
converter           : com.thoughtworks.xstream.converters.reflection.ReflectionConverter
message[1]          : Unable to make field protected transient int java.util.AbstractList.modCount accessible: module java.base does not "opens java.util" to unnamed module @2a79781f
-------------------------------
        at com.thoughtworks.xstream.core.DefaultConverterLookup.lookupConverterForType(DefaultConverterLookup.java:78)
        at com.thoughtworks.xstream.XStream$1.lookupConverterForType(XStream.java:543)
        at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:50)
        at com.thoughtworks.xstream.core.AbstractReferenceMarshaller$1.convertAnother(AbstractReferenceMarshaller.java:88)
        at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshallField(AbstractReflectionConverter.java:269)
        at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.writeField(AbstractReflectionConverter.java:173)
        at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doMarshal(AbstractReflectionConverter.java:262)
        at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshal(AbstractReflectionConverter.java:92)
        at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:69)
        at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:59)
        at com.thoughtworks.xstream.core.AbstractReferenceMarshaller$1.convertAnother(AbstractReferenceMarshaller.java:88)
        at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshallField(AbstractReflectionConverter.java:269)
        at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.writeField(AbstractReflectionConverter.java:173)
        at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doMarshal(AbstractReflectionConverter.java:262)
        at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshal(AbstractReflectionConverter.java:92)
        at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:69)
        at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:59)
        at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:44)
        at com.thoughtworks.xstream.core.TreeMarshaller.start(TreeMarshaller.java:81)
        at com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.marshal(AbstractTreeMarshallingStrategy.java:41)
        at com.thoughtworks.xstream.XStream.marshal(XStream.java:1198)
        at com.thoughtworks.xstream.XStream.marshal(XStream.java:1187)
        at com.thoughtworks.xstream.XStream.toXML(XStream.java:1159)
        at com.thoughtworks.xstream.XStream.toXML(XStream.java:1145)

This is with 1.4.16 and current 1.5.0-SNAPSHOT.

PS: I suppose there is a strong connection to #101.

@famod
Copy link
Contributor Author

famod commented May 9, 2021

Btw, if I use Java 9+ List.of(...) instead of Arrays.asList(...) I'm getting:

com.thoughtworks.xstream.converters.ConversionException:
No converter available
---- Debugging information ----
message             : No converter available
type                : java.util.ImmutableCollections$List12
converter           : com.thoughtworks.xstream.converters.reflection.SerializableConverter
message[1]          : Unable to make private void java.util.ImmutableCollections$List12.readObject(java.io.ObjectInputStream) throws java.io.IOException,java.lang.ClassNotFoundException accessible: module java.base does not "opens java.util" to unnamed module @2a79781f
converter[1]        : com.thoughtworks.xstream.converters.reflection.ReflectionConverter
message[2]          : Unable to make field private final java.lang.Object java.util.ImmutableCollections$List12.e0 accessible: module java.base does not "opens java.util" to unnamed module @2a79781f
-------------------------------

Workaround for this is new ArrayList<>(List.of(...)) and workaround for Collections.emptyList() is new ArrayList<>().

@joehni joehni self-assigned this May 10, 2021
@joehni
Copy link
Member

joehni commented May 10, 2021

Hi,

well, none of this fails (XStream has unit tests for these types running with Java 16), but you have to run XStream in the classpath. I guess, this is not an option for Quarkus. However, the workaround does not produce objects with same behaviour after deserialization. An empty list where you can add objects after deserialization might cause some other surprises.

@famod
Copy link
Contributor Author

famod commented May 10, 2021

Hi and thanks for your feedback!

well, none of this fails

Depends on your POV, but I'm getting a ConversionException while trying to marshal so... 🤷

but you have to run XStream in the classpath

Might be a bit too late for me but I'm not fully sure what that means. There is some classloader juggling in Quarkus but nevertheless XStream is "on the classpath". What am I missing?

However, the workaround does not produce objects with same behaviour after deserialization. An empty list where you can add objects after deserialization might cause some other surprises.

Of course you are right.

@joehni
Copy link
Member

joehni commented May 10, 2021

Depends on your POV

Look at the CI results, if you do not believe it:

  • com.thoughtworks.acceptance.CollectionTest.testEmptyList
  • com.thoughtworks.acceptance.CollectionTest.testListFromArrayAsList

You run XStream in the ModulePath and Java's module system does not allow XStream to access the internals of the referenced classes.

@famod
Copy link
Contributor Author

famod commented May 11, 2021

Hm, I just got confirmation that Quarkus is not doing anything with the module path. Will have to take a deeper dive...

@joehni
Copy link
Member

joehni commented Aug 21, 2021

For Java 16 you'll need option --illegal-access=permit

@joehni joehni closed this as completed Aug 21, 2021
@famod
Copy link
Contributor Author

famod commented Aug 21, 2021

Will this be a requirement also for xstream 1.5?

@xeruf
Copy link

xeruf commented Oct 11, 2021

Shouldn't this flag also work?

--add-opens=java.base/java.util=ALL-UNNAMED

@xeruf
Copy link

xeruf commented Oct 11, 2021

Also, I only get this issue when compiling with JDK 11 and then running on JDK16, compiling on JDK16 fixes it but forces users to upgrade

@vmassol
Copy link

vmassol commented Oct 21, 2021

@joehni Hi. What about java 17 where illegal-access=permit is not working anymore (https://blogs.oracle.com/javamagazine/post/a-peek-into-java-17-continuing-the-drive-to-encapsulate-the-java-runtime-internals). On the XWiki open source project we use XStream (thanks for that!) and we need to start supporting Java 17 at runtime soon. Are there any plans to support Java 17 anytime soon?

Thanks a lot

@xeruf
Copy link

xeruf commented Oct 22, 2021

@vmassol what JDK do you compile on?
For me adding some add-opens to the manifest did it: https://stackoverflow.com/questions/56150697/multiple-add-opens-in-java-jar-manifest

@vmassol
Copy link

vmassol commented Oct 22, 2021

@xeruf Thanks. I don't compile, just execute. I got it to work using the following JVM parameters indeed: --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.io=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.util.concurrent=ALL-UNNAMED

Thanks!

@shoomi
Copy link

shoomi commented Oct 12, 2022

@xeruf Thanks. I don't compile, just execute. I got it to work using the following JVM parameters indeed: --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.io=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.util.concurrent=ALL-UNNAMED

Thanks!

It works for me!

@joehni
Copy link
Member

joehni commented Nov 15, 2022

As you already have noticed, starting with Java 17 you will have to open the modules, which will work also for the older Java versions instead of the --illegal-access option (that no longer exists with Java 17).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants