InaccessibleObjectException with JDK 16
See original GitHub issueGSon (2.8.6) has trouble with JDK 16, seemingly due to https://bugs.openjdk.java.net/browse/JDK-8256358 and https://bugs.openjdk.java.net/browse/JDK-8260600 which prevent access through reflection to JDK internals.
This leads to these errors (for example when trying to serialize an empty list constructed with Collections.emptyList()
) :
java.lang.reflect.InaccessibleObjectException: Unable to make private java.util.Collections$EmptyList() accessible: module java.base does not "opens java.util" to unnamed module @ffaa6af
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.CollectionTypeAdapterFactory.create(CollectionTypeAdapterFactory.java:54)
at com.google.gson.Gson.getDelegateAdapter(Gson.java:541)
at io.gsonfire.gson.WrapTypeAdapterFactory.create(WrapTypeAdapterFactory.java:26)
at com.google.gson.Gson.getAdapter(Gson.java:458)
at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:56)
at com.google.gson.internal.bind.MapTypeAdapterFactory$Adapter.write(MapTypeAdapterFactory.java:208)
at com.google.gson.internal.bind.MapTypeAdapterFactory$Adapter.write(MapTypeAdapterFactory.java:145)
at com.google.gson.Gson.toJson(Gson.java:704)
at com.google.gson.Gson.toJson(Gson.java:683)
...
I would be happy to contribute but I do not even know how to fix this in Gson. Any ideas ?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:17
- Comments:13
Top Results From Across the Web
InaccessibleObjectException (Java SE 16 & JDK 16)
Constructs an InaccessibleObjectException with the given detail message. Method Summary. Methods declared in class java.lang.Throwable · addSuppressed, ...
Read more >java.lang.reflect.InaccessibleObjectException - Stack Overflow
Existing code is working perfectly fine with JDK11 installed. Same lines of code is throwing below error in JDK16
Read more >Build fails with JDK-16 RC2 (InaccessibleObjectException)
Use the newest EAP Idea and JDK-16 Release candidate 2; Make changes to a project; Run it, triggering an automatic build. What is...
Read more >How to run FisPro with JDK >= 16
When running FisPro on JDK 16 or newer, you may get an error similar to the following: InaccessibleObjectException: Unable to make field protected...
Read more >Java 17 Features (with Examples) - HappyCoders.eu
2.1 Before Java 16: Relaxed Strong Encapsulation ... InaccessibleObjectException: Unable to make private java.lang.constant.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@masbaehr, that is unrelated to this issue. As the package name suggests (
com.google.gson.internal
)LinkedTreeMap
is an internalMap
implementation of Gson. This issue has nothing to do with JDK 16; 2.8.6 added a module declaration which enforces that classes from theinternal
package cannot be used. For your case should be able to simply useMap
instead:(Also note that for better type safety should should probably use
TypeToken
.)@Marcono1234 Sure, I wanted to mark it as “workaround available” but could not find how, other than closing it. Reopened !