-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
InaccessibleObjectException with JDK 16 #1875
Comments
The problem might be that the internal class Though I am not sure if this can easily be solved. Maybe the simplest solution which also keeps backward compatibility would be to change this line to handle the exception from gson/gson/src/main/java/com/google/gson/internal/ConstructorConstructor.java Lines 124 to 126 in ceae88b
Though InaccessibleObjectException which is thrown there only exists since Java 9, but this project targets Java 6.Therefore it might be necessary to catch RuntimeException (the subclass).
This is related to #1540, but not the same since here the issue is caused by Gson; Note that I am not a maintainer of this project. Edit: Having |
@tomparle In the case of "gson" library, which uses reflection quite a lot. You still can use it with JDK16. |
Thank you for all your answers. |
Update : I found it too hard to patch gson directly, so in a custom TypeAdapter I check if a type is not accessible (like the private class |
Would you mind leaving the issue open anyways? |
@Marcono1234 Sure, I wanted to mark it as "workaround available" but could not find how, other than closing it. |
@masbaehr, that is unrelated to this issue. As the package name suggests ( Map translationMapR = gson.fromJson(reader, Map.class); (Also note that for better type safety should should probably use |
@tomparle (and everyone else interested), to spare you the duplicate work, I have implemented a potential fix for this in #1902. I don't know when / if the maintainers will merge it, but feel free to try it out and let me know whether is solves this issue. |
@Marcono1234 congratulations for this PR ! |
The change required to fix this was actually not that big, most of it are whitespace changes because I changed the scope of the
Just to make sure we are on the same page: The pull request should exactly handle your use case. Gson only uses the |
Workaround: add Maybe |
Adding |
The official release was not conducted yet, that fixed Java 17 compatibility issue with JEP 403: [1],[2]. [1] google/gson#1875 [2] Strongly Encapsulate JDK Internals https://openjdk.java.net/jeps/403 Change-Id: I2802513866ec3f36be0895a174fc5a22d8b03c3a
Tests like WebSocketResultsOutputIT were failing due to this issue: google/gson#1875
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()
) :I would be happy to contribute but I do not even know how to fix this in Gson. Any ideas ?
The text was updated successfully, but these errors were encountered: