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

Helidon 4.0.2 with JWT Auth fails with UnsupportedCharsetException: UTF-32LE #8195

Closed
mraible opened this issue Jan 4, 2024 · 4 comments · Fixed by #8253
Closed

Helidon 4.0.2 with JWT Auth fails with UnsupportedCharsetException: UTF-32LE #8195

mraible opened this issue Jan 4, 2024 · 4 comments · Fixed by #8253
Assignees
Labels
4.x Version 4.x bug Something isn't working json native-image
Milestone

Comments

@mraible
Copy link

mraible commented Jan 4, 2024

Environment Details

  • Helidon Version: 4.0.2

  • Helidon MP

  • JDK version:

    openjdk 21.0.1 2023-10-17
    OpenJDK Runtime Environment GraalVM CE 21.0.1+12.1 (build 21.0.1+12-jvmci-23.1-b19)
    OpenJDK 64-Bit Server VM GraalVM CE 21.0.1+12.1 (build 21.0.1+12-jvmci-23.1-b19, mixed mode, sharing)

  • OS: macOS


Problem Description

I'm trying to upgrade my Java REST API example to use Helidon 4.0.2 and GraalVM CE 21.0.1.

oktadev/auth0-java-rest-api-examples#58

The last time I ran this example, I used Helidon 4.0.1 and GraalVM CE 21. I don't recall having any issues.

After upgrading, I'm getting the following error when running as a native image and trying to access the /hello endpoint with an access token.

Caused by: java.nio.charset.UnsupportedCharsetException: UTF-32LE
	at java.base@21/java.nio.charset.Charset.forName(Charset.java:543)
	at org.glassfish.json.UnicodeDetectingInputStream.<clinit>(UnicodeDetectingInputStream.java:34)

If I use helidon dev, everything works fine.

I figured if I reverted to GraalVM 21 (sdk install java 21-graalce) and Helidon 4.0.1, it'd fix the problem. However, it still persists after downgrading, so I'm quite confused.

Steps to reproduce

git clone -b jchampions-2024 https://github.com/oktadev/auth0-java-rest-api-examples
cd auth0-java-rest-api-examples/helidon 
mvn package -Pnative-image

Create an Auth0 tenant and copy your domain into src/main/resources/META-INF/microprofile-config.properties.

Create an access token using the Auth0 CLI:

auth0 test token -a https://<your-auth0-domain>/api/v2/ -s openid

Set the returned access token as a TOKEN variable:

TOKEN=...

In a new terminal window, start the Helidon app:

./target/helidon

Access it with the token:

http :8080/hello Authorization:"Bearer $TOKEN"

You'll see the following stacktrace:

2024.01.04 15:42:40 WARNING org.glassfish.jersey.server.ServerRuntime$Responder VirtualThread[#68,[0x3b8763c2 0x0360754f] WebServer socket]/runnable@ForkJoinPool-5-worker-1: An exception mapping did not successfully produce and processed a response. Logging the exception propagated to the default exception mapper.
java.lang.ExceptionInInitializerError
	at org.glassfish.json.JsonParserImpl.<init>(JsonParserImpl.java:71)
	at org.glassfish.json.JsonReaderImpl.<init>(JsonReaderImpl.java:49)
	at org.glassfish.json.JsonReaderFactoryImpl.createReader(JsonReaderFactoryImpl.java:47)
	at io.helidon.security.jwt.jwk.JwkKeys$Builder.resource(JwkKeys.java:150)
	at io.helidon.microprofile.jwt.auth.JwtAuthProvider$Builder.loadPublicKeyJWK(JwtAuthProvider.java:920)
	at io.helidon.microprofile.jwt.auth.JwtAuthProvider$Builder.loadJwkKeys(JwtAuthProvider.java:884)
	at io.helidon.microprofile.jwt.auth.JwtAuthProvider$Builder.getPublicKeyFromContent(JwtAuthProvider.java:873)
	at io.helidon.microprofile.jwt.auth.JwtAuthProvider$Builder.lambda$loadJwkKeysFromLocation$18(JwtAuthProvider.java:821)
	at java.base@21/java.util.Optional.orElseGet(Optional.java:364)
	at io.helidon.microprofile.jwt.auth.JwtAuthProvider$Builder.loadJwkKeysFromLocation(JwtAuthProvider.java:816)
	at java.base@21/java.util.Optional.map(Optional.java:260)
	at io.helidon.microprofile.jwt.auth.JwtAuthProvider$Builder.createJwkKeys(JwtAuthProvider.java:797)
	at io.helidon.microprofile.jwt.auth.JwtAuthProvider$Builder.lambda$build$0(JwtAuthProvider.java:656)
	at io.helidon.common.LazyValueImpl.get(LazyValueImpl.java:118)
	at io.helidon.microprofile.jwt.auth.JwtAuthProvider.lambda$authenticate$1(JwtAuthProvider.java:278)
	at java.base@21/java.util.Optional.map(Optional.java:260)
	at io.helidon.microprofile.jwt.auth.JwtAuthProvider.authenticate(JwtAuthProvider.java:249)
	at io.helidon.microprofile.jwt.auth.JwtAuthProvider.lambda$authenticate$0(JwtAuthProvider.java:224)
	at java.base@21/java.util.Optional.map(Optional.java:260)
	at io.helidon.microprofile.jwt.auth.JwtAuthProvider.authenticate(JwtAuthProvider.java:224)
	at io.helidon.security.AuthenticationClientImpl.authenticate(AuthenticationClientImpl.java:74)
	at java.base@21/java.util.Optional.map(Optional.java:260)
	at io.helidon.security.AuthenticationClientImpl.submit(AuthenticationClientImpl.java:44)
	at io.helidon.security.AuthenticationClientImpl.submit(AuthenticationClientImpl.java:25)
	at io.helidon.security.SecurityClientBuilder.submit(SecurityClientBuilder.java:68)
	at io.helidon.microprofile.security.SecurityFilterCommon.processAuthentication(SecurityFilterCommon.java:192)
	at io.helidon.microprofile.security.SecurityFilterCommon.authenticate(SecurityFilterCommon.java:162)
	at io.helidon.microprofile.security.SecurityFilter.processSecurity(SecurityFilter.java:151)
	at io.helidon.microprofile.security.SecurityFilterCommon.doFilter(SecurityFilterCommon.java:135)
	at io.helidon.microprofile.security.SecurityFilter.filter(SecurityFilter.java:137)
	at org.glassfish.jersey.server.ContainerFilteringStage.apply(ContainerFilteringStage.java:108)
	at org.glassfish.jersey.server.ContainerFilteringStage.apply(ContainerFilteringStage.java:44)
	at org.glassfish.jersey.process.internal.Stages.process(Stages.java:173)
	at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:253)
	at org.glassfish.jersey.internal.Errors$1.call(Errors.java:248)
	at org.glassfish.jersey.internal.Errors$1.call(Errors.java:244)
	at org.glassfish.jersey.internal.Errors.process(Errors.java:292)
	at org.glassfish.jersey.internal.Errors.process(Errors.java:274)
	at org.glassfish.jersey.internal.Errors.process(Errors.java:244)
	at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:265)
	at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:240)
	at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:697)
	at io.helidon.microprofile.server.JaxRsService.doHandle(JaxRsService.java:227)
	at io.helidon.microprofile.server.JaxRsService.lambda$handle$2(JaxRsService.java:185)
	at io.helidon.common.context.Contexts.runInContext(Contexts.java:117)
	at io.helidon.microprofile.server.JaxRsService.handle(JaxRsService.java:185)
	at io.helidon.webserver.http.HttpRouting$RoutingExecutor.doRoute(HttpRouting.java:668)
	at io.helidon.webserver.http.HttpRouting$RoutingExecutor.call(HttpRouting.java:627)
	at io.helidon.webserver.http.HttpRouting$RoutingExecutor.call(HttpRouting.java:605)
	at io.helidon.webserver.http.ErrorHandlers.runWithErrorHandling(ErrorHandlers.java:75)
	at io.helidon.webserver.http.Filters$FilterChainImpl.proceed(Filters.java:121)
	at io.helidon.webserver.observe.metrics.MetricsFeature.lambda$configureVendorMetrics$2(MetricsFeature.java:90)
	at io.helidon.webserver.http.Filters$FilterChainImpl.proceed(Filters.java:119)
	at io.helidon.webserver.security.SecurityContextFilter.filter(SecurityContextFilter.java:88)
	at io.helidon.webserver.http.Filters$FilterChainImpl.proceed(Filters.java:119)
	at io.helidon.common.context.Contexts.runInContext(Contexts.java:117)
	at io.helidon.webserver.context.ContextRoutingFeature.filter(ContextRoutingFeature.java:50)
	at io.helidon.webserver.http.Filters$FilterChainImpl.proceed(Filters.java:119)
	at io.helidon.webserver.http.Filters.executeFilters(Filters.java:87)
	at io.helidon.webserver.http.Filters.lambda$filter$0(Filters.java:83)
	at io.helidon.webserver.http.ErrorHandlers.runWithErrorHandling(ErrorHandlers.java:75)
	at io.helidon.webserver.http.Filters.filter(Filters.java:83)
	at io.helidon.webserver.http.HttpRouting.route(HttpRouting.java:109)
	at io.helidon.webserver.http1.Http1Connection.route(Http1Connection.java:350)
	at io.helidon.webserver.http1.Http1Connection.handle(Http1Connection.java:187)
	at io.helidon.webserver.ConnectionHandler.run(ConnectionHandler.java:165)
	at io.helidon.common.task.InterruptableTask.call(InterruptableTask.java:47)
	at io.helidon.webserver.ThreadPerTaskExecutor$ThreadBoundFuture.run(ThreadPerTaskExecutor.java:239)
	at java.base@21/java.lang.VirtualThread.runWith(VirtualThread.java:341)
	at java.base@21/java.lang.VirtualThread.run(VirtualThread.java:311)
	at java.base@21/java.lang.VirtualThread$VThreadContinuation$1.run(VirtualThread.java:192)
Caused by: java.nio.charset.UnsupportedCharsetException: UTF-32LE
	at java.base@21/java.nio.charset.Charset.forName(Charset.java:543)
	at org.glassfish.json.UnicodeDetectingInputStream.<clinit>(UnicodeDetectingInputStream.java:34)
	... 71 more

2024.01.04 15:42:40 WARNING io.helidon.webserver.http.ErrorHandlers VirtualThread[#68,[0x3b8763c2 0x0360754f] WebServer socket]/runnable@ForkJoinPool-5-worker-1: [0x3b8763c2 0x0360754f] Request failed: HttpPrologue[protocol=HTTP, protocolVersion=1.1, method=GET, uriPath=/hello, query=, fragment=], cannot send error response, as response already sent
io.helidon.http.RequestException: Internal exception in JAX-RS processing
	at io.helidon.http.RequestException$Builder.build(RequestException.java:139)
	at io.helidon.webserver.http.ErrorHandlers.unhandledError(ErrorHandlers.java:194)
	at io.helidon.webserver.http.ErrorHandlers.runWithErrorHandling(ErrorHandlers.java:113)
	at io.helidon.webserver.http.Filters$FilterChainImpl.proceed(Filters.java:121)
	at io.helidon.webserver.observe.metrics.MetricsFeature.lambda$configureVendorMetrics$2(MetricsFeature.java:90)
	at io.helidon.webserver.http.Filters$FilterChainImpl.proceed(Filters.java:119)
	at io.helidon.webserver.security.SecurityContextFilter.filter(SecurityContextFilter.java:88)
	at io.helidon.webserver.http.Filters$FilterChainImpl.proceed(Filters.java:119)
	at io.helidon.common.context.Contexts.runInContext(Contexts.java:117)
	at io.helidon.webserver.context.ContextRoutingFeature.filter(ContextRoutingFeature.java:50)
	at io.helidon.webserver.http.Filters$FilterChainImpl.proceed(Filters.java:119)
	at io.helidon.webserver.http.Filters.executeFilters(Filters.java:87)
	at io.helidon.webserver.http.Filters.lambda$filter$0(Filters.java:83)
	at io.helidon.webserver.http.ErrorHandlers.runWithErrorHandling(ErrorHandlers.java:75)
	at io.helidon.webserver.http.Filters.filter(Filters.java:83)
	at io.helidon.webserver.http.HttpRouting.route(HttpRouting.java:109)
	at io.helidon.webserver.http1.Http1Connection.route(Http1Connection.java:350)
	at io.helidon.webserver.http1.Http1Connection.handle(Http1Connection.java:187)
	at io.helidon.webserver.ConnectionHandler.run(ConnectionHandler.java:165)
	at io.helidon.common.task.InterruptableTask.call(InterruptableTask.java:47)
	at io.helidon.webserver.ThreadPerTaskExecutor$ThreadBoundFuture.run(ThreadPerTaskExecutor.java:239)
	at java.base@21/java.lang.VirtualThread.runWith(VirtualThread.java:341)
	at java.base@21/java.lang.VirtualThread.run(VirtualThread.java:311)
	at java.base@21/java.lang.VirtualThread$VThreadContinuation$1.run(VirtualThread.java:192)
Caused by: io.helidon.http.InternalServerException: Internal exception in JAX-RS processing
	at io.helidon.microprofile.server.JaxRsService.doHandle(JaxRsService.java:247)
	at io.helidon.microprofile.server.JaxRsService.lambda$handle$2(JaxRsService.java:185)
	at io.helidon.common.context.Contexts.runInContext(Contexts.java:117)
	at io.helidon.microprofile.server.JaxRsService.handle(JaxRsService.java:185)
	at io.helidon.webserver.http.HttpRouting$RoutingExecutor.doRoute(HttpRouting.java:668)
	at io.helidon.webserver.http.HttpRouting$RoutingExecutor.call(HttpRouting.java:627)
	at io.helidon.webserver.http.HttpRouting$RoutingExecutor.call(HttpRouting.java:605)
	at io.helidon.webserver.http.ErrorHandlers.runWithErrorHandling(ErrorHandlers.java:75)
	... 21 more
Caused by: io.helidon.http.InternalServerException: Failed to process JAX-RS request
	at io.helidon.microprofile.server.JaxRsService$JaxRsResponseWriter.failure(JaxRsService.java:376)
	at org.glassfish.jersey.server.ServerRuntime$Responder.process(ServerRuntime.java:456)
	at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:269)
	at org.glassfish.jersey.internal.Errors$1.call(Errors.java:248)
	at org.glassfish.jersey.internal.Errors$1.call(Errors.java:244)
	at org.glassfish.jersey.internal.Errors.process(Errors.java:292)
	at org.glassfish.jersey.internal.Errors.process(Errors.java:274)
	at org.glassfish.jersey.internal.Errors.process(Errors.java:244)
	at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:265)
	at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:240)
	at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:697)
	at io.helidon.microprofile.server.JaxRsService.doHandle(JaxRsService.java:227)
	... 28 more
Caused by: java.lang.ExceptionInInitializerError
	at org.glassfish.json.JsonParserImpl.<init>(JsonParserImpl.java:71)
	at org.glassfish.json.JsonReaderImpl.<init>(JsonReaderImpl.java:49)
	at org.glassfish.json.JsonReaderFactoryImpl.createReader(JsonReaderFactoryImpl.java:47)
	at io.helidon.security.jwt.jwk.JwkKeys$Builder.resource(JwkKeys.java:150)
	at io.helidon.microprofile.jwt.auth.JwtAuthProvider$Builder.loadPublicKeyJWK(JwtAuthProvider.java:920)
	at io.helidon.microprofile.jwt.auth.JwtAuthProvider$Builder.loadJwkKeys(JwtAuthProvider.java:884)
	at io.helidon.microprofile.jwt.auth.JwtAuthProvider$Builder.getPublicKeyFromContent(JwtAuthProvider.java:873)
	at io.helidon.microprofile.jwt.auth.JwtAuthProvider$Builder.lambda$loadJwkKeysFromLocation$18(JwtAuthProvider.java:821)
	at java.base@21/java.util.Optional.orElseGet(Optional.java:364)
	at io.helidon.microprofile.jwt.auth.JwtAuthProvider$Builder.loadJwkKeysFromLocation(JwtAuthProvider.java:816)
	at java.base@21/java.util.Optional.map(Optional.java:260)
	at io.helidon.microprofile.jwt.auth.JwtAuthProvider$Builder.createJwkKeys(JwtAuthProvider.java:797)
	at io.helidon.microprofile.jwt.auth.JwtAuthProvider$Builder.lambda$build$0(JwtAuthProvider.java:656)
	at io.helidon.common.LazyValueImpl.get(LazyValueImpl.java:118)
	at io.helidon.microprofile.jwt.auth.JwtAuthProvider.lambda$authenticate$1(JwtAuthProvider.java:278)
	at java.base@21/java.util.Optional.map(Optional.java:260)
	at io.helidon.microprofile.jwt.auth.JwtAuthProvider.authenticate(JwtAuthProvider.java:249)
	at io.helidon.microprofile.jwt.auth.JwtAuthProvider.lambda$authenticate$0(JwtAuthProvider.java:224)
	at java.base@21/java.util.Optional.map(Optional.java:260)
	at io.helidon.microprofile.jwt.auth.JwtAuthProvider.authenticate(JwtAuthProvider.java:224)
	at io.helidon.security.AuthenticationClientImpl.authenticate(AuthenticationClientImpl.java:74)
	at java.base@21/java.util.Optional.map(Optional.java:260)
	at io.helidon.security.AuthenticationClientImpl.submit(AuthenticationClientImpl.java:44)
	at io.helidon.security.AuthenticationClientImpl.submit(AuthenticationClientImpl.java:25)
	at io.helidon.security.SecurityClientBuilder.submit(SecurityClientBuilder.java:68)
	at io.helidon.microprofile.security.SecurityFilterCommon.processAuthentication(SecurityFilterCommon.java:192)
	at io.helidon.microprofile.security.SecurityFilterCommon.authenticate(SecurityFilterCommon.java:162)
	at io.helidon.microprofile.security.SecurityFilter.processSecurity(SecurityFilter.java:151)
	at io.helidon.microprofile.security.SecurityFilterCommon.doFilter(SecurityFilterCommon.java:135)
	at io.helidon.microprofile.security.SecurityFilter.filter(SecurityFilter.java:137)
	at org.glassfish.jersey.server.ContainerFilteringStage.apply(ContainerFilteringStage.java:108)
	at org.glassfish.jersey.server.ContainerFilteringStage.apply(ContainerFilteringStage.java:44)
	at org.glassfish.jersey.process.internal.Stages.process(Stages.java:173)
	at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:253)
	... 37 more
Caused by: java.nio.charset.UnsupportedCharsetException: UTF-32LE
	at java.base@21/java.nio.charset.Charset.forName(Charset.java:543)
	at org.glassfish.json.UnicodeDetectingInputStream.<clinit>(UnicodeDetectingInputStream.java:34)
	... 71 more
@ljnelson
Copy link
Member

ljnelson commented Jan 4, 2024

For posterity, this is failing, I guess, in your environment, correct? (For completeness, both Helidon 4.0.1 and 4.0.2 use Parsson 1.1.5, I guess.)

https://github.com/eclipse-ee4j/parsson/blob/1.1.5/impl/src/main/java/org/eclipse/parsson/UnicodeDetectingInputStream.java#L34

That smells to me like not all character sets are available at runtime and probably something like AddAllCharsets or the like needs to be added ideally to Parsson or, temporarily, to your application. See https://github.com/oracle/graal/blob/master/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/localization/LocalizationFeature.java#L179-L180; hard to find documentation on this.

@ljnelson
Copy link
Member

ljnelson commented Jan 4, 2024

@mraible
Copy link
Author

mraible commented Jan 5, 2024

If I change my native-image.properties to add all charsets, it solves the problem:

Args=--initialize-at-build-time=com.okta.rest \
  --initialize-at-run-time=io.helidon.openapi.ExpandedTypeDescription \
  --report-unsupported-elements-at-runtime \
  -H:+AddAllCharsets

@danielkec
Copy link
Contributor

Confirmed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.x Version 4.x bug Something isn't working json native-image
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

5 participants