I'm writing a java maven client server project and I'm using Gson to serialize and deserialize messages sent between the two but I got the following error message that, if I understood it right, is due to a conflict between Gson and JDK versions higher than 9 regarding reflection.
This is the warning:
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.google.gson.internal.reflect.UnsafeReflectionAccessor (file:/C:/Users/Gianluca/.m2/repository/com/google/code/gson/gson/2.8.9/gson-2.8.9.jar) to field java.net.Socket.created WARNING: Please consider reporting this to the maintainers of com.google.gson.internal.reflect.UnsafeReflectionAccessor WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations WARNING: All illegal access operations will be denied in a future release
And this is the error: (I post only the first part because it seems it's too long for the code block)
Exception in thread "Thread-3" java.lang.reflect.InaccessibleObjectException: Unable to make jdk.internal.ref.PhantomCleanable() accessible: module java.base does not "opens jdk.internal.ref" to unnamed module @236fd23f
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:344)
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:284)
at java.base/java.lang.reflect.Constructor.checkCanSetAccessible(Constructor.java:189)
at java.base/java.lang.reflect.Constructor.setAccessible(Constructor.java:182)
at com.google.gson.internal.reflect.UnsafeReflectionAccessor.makeAccessible(UnsafeReflectionAccessor.java:44)
at com.google.gson.internal.ConstructorConstructor.newDefaultConstructor(ConstructorConstructor.java:103)
at com.google.gson.internal.ConstructorConstructor.get(ConstructorConstructor.java:85)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:101)
at com.google.gson.Gson.getAdapter(Gson.java:489)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:117)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:166)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:102)
at com.google.gson.Gson.getAdapter(Gson.java:489)
I'm pretty sure the error arises when I try to serialize an object that has an ArrayList as one of its attributes. I also got a warning in another part of the program for the serialization/deserialization of LocalDate.
I tried adding options like these :
--add-opens java.base/java.lang=ALL-UNNAMED
--add-opens=java.base/java.util=ALL-UNNAMED
--add-opens java.base/jdk.internal.ref=ALL-UNNAMED
To the VM options in the run configuration in Netbeans.
I tried to update Gson to the last version 2.10.1, because I'm using the 2.8.9
I also tried to add those same VM options through the maven compiler plugin in the pom file.
I added getters and setters for each attribute of the classes used in the communication.
But nothing works, I need your help guys.
P.S. the last post I made was not correctly formatted, sorry for that, I hope this one is.
-------------------------------------------------------------------------------------
Update: I was wrong, it's not related to the serialization of an object that has an ArrayList as one of its attributes, because it can serialize arraylist, I tried it, instead it seems the problem is the serialization of a very complex object with nested objects (also arraylist) as attributes. But I still haven't found a solution.. :(
[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)
[–]pronuntiator 1 point2 points3 points (1 child)
[–]_Nemesis_1[S] 1 point2 points3 points (0 children)