-
Notifications
You must be signed in to change notification settings - Fork 1.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
java.lang.reflect.InaccessibleObjectException when using parseUnsecuredClaims() v0.12.1 Java 17 #854
Comments
@FreEZer00 , I see, thank you. It seems as if our edit yesterday was placed 'too late' during class initialization for certain use cases. I'll see about getting a follow-up release out today that initializes sooner, in the appropriate place. |
So I ran a test in a completely separate project/jvm using this test class: package test;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Header;
import io.jsonwebtoken.Jwt;
import io.jsonwebtoken.Jwts;
public class Main {
public static void main(String[] args) {
String token = "eyJhbGciOiJub25lIn0.eyJzdWIiOiJKb2UifQ.";
Jwt<Header, Claims> jwt = Jwts.parser().unsecured().build().parseUnsecuredClaims(token);
System.out.println("jwt: " + jwt);
}
} When there is no module JJWT.Standalone.Test {
requires jjwt.api;
} will result in the test failing. I'm digging in now to see if there's an easy enough workaround. Thank you again for reporting the issue! |
The policies of reflection have changed since JDK 9. I tried running it on JDK 8, it worked well. Later on JDK 17, you need to pass these JVM Arguments while deploying your application.
For JDK17 reference: https://confluence.atlassian.com/jiracore/java-17-runtime-opens-and-exports-arguments-1188413810.html |
@stasim101 correct, but you don't need to open that up for all modules, if you do have a
|
- Replaced ByteArrayInputStream reflection with new BytesInputStream implementation. The reflection is what required --add-opens java.base/java.io=jjwt.api on JDK 17+. - Refactored KeysBridge to perform our own key length logic instead of delegating to sun.security.util.KeyUtil. The reflection is what required --add-opens java.base/sun.security.util=jjwt.api on JDK 17+ - Removed AddOpens.java due to above refactoring (no longer needed).
- Replaced ByteArrayInputStream reflection with new BytesInputStream implementation. The reflection is what required --add-opens java.base/java.io=jjwt.api on JDK 17+. - Refactored KeysBridge to perform our own key length logic instead of delegating to sun.security.util.KeyUtil. The reflection is what required --add-opens java.base/sun.security.util=jjwt.api on JDK 17+ - Removed AddOpens.java due to above refactoring (no longer needed). - Returned a test-only --add-opens for sun.security.util for 3 test cases (added to test.addOpens maven property)
* Closes #854. - Replaced `ByteArrayInputStream` reflection with new `BytesInputStream` implementation. The reflection is what required `--add-opens java.base/java.io=jjwt.api` on JDK 17+. - Refactored `KeysBridge` to perform our own key length logic instead of delegating to `sun.security.util.KeyUtil`. The reflection is what required `--add-opens java.base/sun.security.util=jjwt.api` on JDK 17+ - Removed `AddOpens.java` due to above refactoring (no longer needed). - Returned a test-only `--add-opens` for `sun.security.util` for 3 test cases (added to `test.addOpens` maven property)
Resolved in the 0.12.2 release (no more |
Describe the bug
Currently when trying to upgrade to the latest release the method parseUnsecuredClaims throws an InaccessibleObjectException.
v0.12.1 Java 17
To Reproduce
Steps to reproduce the behavior:
Jwts.parser().build();
jwtParser.parseUnsecuredClaims(jwtString)
Exception thrown in
io.jsonwebtoken.lang.Classes
line 346Expected behavior
JWT parsed successfully and claims are returned properly
The text was updated successfully, but these errors were encountered: