cloud-sql-jdbc-socket-factory icon indicating copy to clipboard operation
cloud-sql-jdbc-socket-factory copied to clipboard

IllegalAccessError when trying to build Java 17 Native image

Open luisospina-sealed opened this issue 2 years ago • 3 comments

While trying to build a simple Micronaut app with a connection to a SQL (postgres) db an IllegalAccessError is being thrown. Here's the stack trace

Fatal error: java.lang.IllegalAccessError: class com.google.cloud.sql.nativeimage.CloudSqlFeature (in unnamed module @0x3c3cd7a5) cannot access class org.graalvm.nativeimage.impl.ConfigurationCondition (in module org.graalvm.sdk) because module org.graalvm.sdk does not export org.graalvm.nativeimage.impl to unnamed module @0x3c3cd7a5 at com.google.cloud.sql.nativeimage.CloudSqlFeature.beforeAnalysis(CloudSqlFeature.java:57) at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.lambda$runPointsToAnalysis$9(NativeImageGenerator.java:722) at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.FeatureHandler.forEachFeature(FeatureHandler.java:78) at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.runPointsToAnalysis(NativeImageGenerator.java:722) at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:564) at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:521) at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:407) at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:585) at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:128)

The error comes from the dependency implementation("com.google.cloud.sql:postgres-socket-factory:1.7.0")

In case it helps, this is the Dockerfile being used (which is auto-generated by Micronaut):

FROM ghcr.io/graalvm/native-image:ol7-java17-22.2.0 AS graalvm WORKDIR /home/app COPY layers/libs /home/app/libs COPY layers/classes /home/app/classes COPY layers/resources /home/app/resources COPY layers/application.jar /home/app/application.jar RUN mkdir /home/app/config-dirs COPY config-dirs/generateResourcesConfigFile /home/app/config-dirs/generateResourcesConfigFile RUN native-image -cp /home/app/libs/*.jar:/home/app/resources:/home/app/application.jar --no-fallback -H:Name=application -J--add-exports=org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk=ALL-UNNAMED -J--add-exports=org.graalvm.nativeimage.builder/com.oracle.svm.core.configure=ALL-UNNAMED -H:ConfigurationFileDirectories=/home/app/config-dirs/generateResourcesConfigFile -H:Class=com.products.Application FROM frolvlad/alpine-glibc:alpine-3.12 RUN apk update && apk add libstdc++ COPY --from=graalvm /home/app/application /app/application ENTRYPOINT ["/app/application"]

Let me know if you need any other info to make this error clear.

luisospina-sealed avatar Sep 30 '22 15:09 luisospina-sealed

Hi @luisospina-sealed, thanks for opening this issue! We will investigate further and get back to you soon.

shubha-rajan avatar Sep 30 '22 16:09 shubha-rajan

Downgrading to p2 based on some initial investigation by Shubha, this seems specifically limited to J17 w/ Graal.

kurtisvg avatar Oct 11 '22 16:10 kurtisvg

Exactly the same happens to me with v1.7.0.

javamachr avatar Oct 14 '22 11:10 javamachr