question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

InaccessibleObjectException with JDK 16

See original GitHub issue

GSon (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:closed
  • Created 3 years ago
  • Reactions:17
  • Comments:13

github_iconTop GitHub Comments

2reactions
Marcono1234commented, Jun 9, 2021

@masbaehr, that is unrelated to this issue. As the package name suggests (com.google.gson.internal) LinkedTreeMap is an internal Map implementation of Gson. This issue has nothing to do with JDK 16; 2.8.6 added a module declaration which enforces that classes from the internal package cannot be used. For your case should be able to simply use Map instead:

Map translationMapR = gson.fromJson(reader, Map.class);

(Also note that for better type safety should should probably use TypeToken.)

2reactions
tomparlecommented, May 4, 2021

@Marcono1234 Sure, I wanted to mark it as “workaround available” but could not find how, other than closing it. Reopened !

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found