-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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 records don't work in native image with GraalVM 21.3.0 JDK 17 #20891
Comments
smallrye/smallrye-graphql#1045 Record support for graphql is not yet in quarkus. And you need some extra config. |
The GraphQL example works in JVM mode. but don't let yourself distracte from the GraphQL thing, it happens with pure REST as well (even with Jackson, which supports records ootb) |
I added --report-unsupported-elements-at-runtime to quarkus.native.additional-build-args on the pom.xml and It worked. |
Well, that will eventually lead to a failure during runtime, wouldn't it? Not what I desire :) |
@zakkak this is still an issue with the released version of |
@geoand not much. After looking a bit into it, it appears to be an issue with smallrye-config not being native-image friendly and not with Java records support in GraalVM or Quarkus. GraalVM doesn't provide Two options I see are:
HTH |
Thanks @zakkak |
I'll have a look. |
After posting the above answer I got another idea to try and toying around a bit more with records and GraalVM 21.3 I was able to replicate the issue without Quarkus or smallrye. You can find the reproducer here https://github.com/zakkak/issue-reproducers/tree/record-annotations-21.3 I am going to have a better look and open an upstream issue after all. @radcortez sorry for the false alarm |
Very interesting @zakkak. Do you plan to open an issue on GraalVM? |
Upstream GraalVM issue: oracle/graal#3984 |
Same issue here. Working adding |
A bit of more information and less dependencies: Given package org.acme;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@Path("/hello")
public class GreetingResource {
@GET
@Produces(MediaType.TEXT_PLAIN)
public String hello() {
System.out.printf(new Thing("asd").toString());
return "Hello RESTEasy";
}
} and package org.acme;
import io.quarkus.runtime.annotations.RegisterForReflection;
@RegisterForReflection
public record Thing(String aValue) {
} things fail. This happens as soon as a record is registered for reflection with one or the other mechanism. Quarkus 2.7.1, GraalVM 21.3 Java17.
|
any progress so far? |
haven't tested myself, but it looks like Mandrel 21.3.1.1 fixes this issue: |
Upstream Graal VM will have this fixed in 21.3.2 and 22.1 releases (April 2022). Mandrel included this fix in |
In my case I have the issue when instantiating a record. If record is declared, but the instantiation is not called, then native-image works. In fact, using a JSON as a response (i.e which will be deserialized), works perfectly well. |
package org.acme;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@Path("/hello")
public class GreetingResource {
@GET
@Produces(MediaType.TEXT_PLAIN)
public String hello() {
System.out.printf(new Thing("asd").toString());
return "Hello RESTEasy";
}
} Based on the above reproducer given by @michael-simons I could reproduce it with Fails: Is fixed if you use Works: Or directly you can use |
Closing this as Quarkus |
Describe the bug
Java 17 records don't work with GraalVM 21.3.0 when used as return types of resources that produce
application/json
. They also fail with SmallRye GraphQL.In the reproducer I used
quarkus-resteasy-jackson
because Jackson supports records out of the box without any configuration.When I create a native image like that with GraalVM 21.3 it works as expected.
Expected behavior
Quarkus native should produce a binary.
Actual behavior
Native compilation fails with:
How to Reproduce?
Given the following dependency:
This
record
:and the following resource
A request like
curl localhost:8080/hello
returnsThe whole project is here: restrecords.zip
Reproduce with
on GraalVM 21.3 Java 17
An example using SmallRye GraphQL is available here: https://github.com/michael-simons/neo4j-aura-quarkus-graphql/tree/jdk17
Output of
uname -a
orver
Darwin bs62.XXX 20.6.0 Darwin Kernel Version 20.6.0: Mon Aug 30 06:12:21 PDT 2021; root:xnu-7195.141.6~3/RELEASE_X86_64 x86_64
Output of
java -version
openjdk version "17.0.1" 2021-10-19 OpenJDK Runtime Environment GraalVM CE 21.3.0 (build 17.0.1+12-jvmci-21.3-b05) OpenJDK 64-Bit Server VM GraalVM CE 21.3.0 (build 17.0.1+12-jvmci-21.3-b05, mixed mode, sharing)
GraalVM version (if different from Java)
21.3.0
Quarkus version or git rev
2.3.0
Build tool (ie. output of
mvnw --version
orgradlew --version
)Apache Maven 3.8.1 (05c21c65bdfed0f71a2f2ada8b84da59348c4c5d)
Additional information
No response
The text was updated successfully, but these errors were encountered: