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

java 17 support #1963

Closed
just1602 opened this issue Sep 14, 2021 · 5 comments
Closed

java 17 support #1963

just1602 opened this issue Sep 14, 2021 · 5 comments

Comments

@just1602
Copy link

Hello!

I try to update an application that use Gson to java 17 this morning and I get the following warning and error :

WARNING: Illegal reflective access by com.google.gson.internal.reflect.UnsafeReflectionAccessor (file:/app/libs/gson-2.8.7.jar) to constructor java.lang.StackTraceElement()
java.lang.reflect.InaccessibleObjectException: Unable to make private java.lang.StackTraceElement() accessible: module java.base does not "opens java.lang" to unnamed module 

I was wondering if there was plan to make Gson compatible with java 17 since reflexive call to internal API isn't allowed anymore?

A blog article about the java runtime encapsulation : https://blogs.oracle.com/javamagazine/java-runtime-encapsulation-internals

@Marcono1234
Copy link
Collaborator

Marcono1234 commented Sep 14, 2021

Gson will only perform perform illegal access when you try to serialize or deserialize a third-party class without having a custom type adapter specified (and for which no built-in adapter exists). In your case it sounds like you are trying to deserialize java.lang.StackTraceElement. Could you please check if that is the case?


Note that I am not a maintainer of this project.

@just1602
Copy link
Author

Thanks! I'll check this out and try to create a type adapter for this class that is use in one of our library. :)

@piegamesde
Copy link

Please reopen. There definitely should be a built-in type adapter in GSON for types like Exception and StackTraceElement.

@Marcono1234
Copy link
Collaborator

@piegamesde, this issue was specifically about being unable to use reflection for JDK classes. The previous functionality was inherently unreliable because it depended on JDK internals.
If you think Gson should provide built-in adapters for Exception (or even Throwable) and StackTraceElement feel free to create a new feature request issue.

(This is also related to #469)

@Marcono1234
Copy link
Collaborator

There is now a feature request for proper support for Throwable: #2352

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

No branches or pull requests

3 participants