magro / kryo-serializers

More kryo serializers
Apache License 2.0
381 stars 120 forks source link

Compatibility with JDK 17 #131

Open lvitaly opened 3 years ago

jvdvegt commented 3 years ago

I suppose what @lvitaly means is: ArraysAsListSerializer is currently not compatible with Java 17, as a java.lang.reflect.InaccessibleObjectException is thrown when the class is created. This is no longer allowed:

public ArraysAsListSerializer() {
        _arrayField = Class.forName( "java.util.Arrays$ArrayList" ).getDeclaredField( "a" );
        _arrayField.setAccessible( true );
}

Are there any plans to fix this?

lvitaly commented 3 years ago

Sorry that I opened an issue without comment. @jvdvegt, I guess you are right, but I discovered that kryo added this serializer to the default list in v5.0.0 (see Kryo.java#L225).

I discovered few more serializers that throw errors with JDK 17

Unfortunately, I didn't dig deep enough to find out the root cause, and here is an original thread with these issues in cqengine project (see https://github.com/npgall/cqengine/issues/269). You can find there that almost all cqengine's tests except one (ReflectiveAttributeTest) are passing with JDK17 + kryo v5.2.0 without serializers mentioned above.

jvdvegt commented 3 years ago

The first one seems quite easy to fix, though it is slightly slower than the original version. See attached sourcecode. UnmodifiableCollectionsSerializer.java.txt

dkroehan commented 2 years ago

Stumbled across the issue with the UnmodifiableCollectionsSerializer when I was trying JDK 17 with kryo + kryo-serializers.

The stacktrace is:

checkCanSetAccessible:354, AccessibleObject (java.lang.reflect)
checkCanSetAccessible:297, AccessibleObject (java.lang.reflect)
checkCanSetAccessible:178, Field (java.lang.reflect)
setAccessible:172, Field (java.lang.reflect)
<clinit>:55, UnmodifiableCollectionsSerializer (de.javakaffee.kryoserializers)

The error message is: Unable to make field final java.util.Collection java.util.Collections$UnmodifiableCollection.c accessible: module java.base does not "opens java.util" to unnamed module @61322f9d

tinder-johnbuhanan commented 1 year ago

Any updates on ArraysAsListSerializer compatibility with JDK 17?

theigl commented 1 year ago

@tinder-johnbuhanan: Can't you simply use the built-in ArraysAsListSerializer from Kryo 5? If you are on Kryo 5, you don't need any custom serializers. If you are on Kryo 4, you can copy the ArraysAsListSerializer from Kryo 5.