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

[GR-48812] Native builds fail with most recent GraalVM 17 versions #7089

Closed
DarkAtra opened this issue Jul 31, 2023 · 9 comments
Closed

[GR-48812] Native builds fail with most recent GraalVM 17 versions #7089

DarkAtra opened this issue Jul 31, 2023 · 9 comments
Assignees
Labels

Comments

@DarkAtra
Copy link

DarkAtra commented Jul 31, 2023

Describe the issue

When building my project using one of the more recent GraalVM versions (graalvm-jdk-17_macos-x64_bin/17.0.0/x64/graalvm-jdk-17.0.8+9.1) the following error occurs:

> com.oracle.svm.core.util.VMError$HostedError: com.oracle.svm.core.util.UserError$UserException: Image heap writing found a class not seen during static analysis. Did a static field or an object referenced from a static field change during native image generation? For example, a lazily initialized cache could have been initialized during image generation, in which case you need to force eager initialization of the cache before static analysis or reset the cache using a field value recomputation.
    class: dev.kord.common.entity.optional.Optional$Missing$Companion
  reachable through:
    object: [Ljava.lang.Class;@3a2ff431  of class: java.lang.Class[]
    object: com.oracle.svm.core.code.ImageCodeInfo@4be4e3ff  of class: com.oracle.svm.core.code.ImageCodeInfo
    root: com.oracle.svm.core.code.ImageCodeInfo.prepareCodeInfo()

Optional$Missing is implemented as follows:

public sealed class Optional<out T> {

    public class Missing<out T> private constructor() : Optional<T>() {

        // ... irrelevant code here

        public companion object {
            private val constantNull = Missing<Nothing>()

            public operator fun <T : Any> invoke(): Missing<T> = constantNull
        }
    }
}

I don't get how the value of constantNull could change in this situation as it's literally a val (e.g. final). Downgrading to graalvm-ce-java17-darwin/22.3.2/x64/graalvm-ce-java17-22.3.2 fixes the issue.

Steps to reproduce the issue

  1. ensure you have GraalVM graalvm-jdk-17.0.8+9.1 installed and set as JAVA_HOME
  2. git clone [email protected]:DarkAtra/v-rising-discord-bot.git
  3. ./mvnw -PnativeTest clean verify

There's also a github workflow run with the exact same environment and error here: https://github.com/DarkAtra/v-rising-discord-bot/actions/runs/5685610328/job/15410839417#step:4:448
Also, here's the run with the downgraded GraalVM version: https://github.com/DarkAtra/v-rising-discord-bot/actions/runs/5706950594/job/15463156901

Describe GraalVM and your environment:

  • GraalVM version: graalvm-jdk-17_macos-x64_bin/17.0.0/x64/graalvm-jdk-17.0.8+9.1
  • JDK major version: 17
  • OS: macOS 12 Monterey
  • Architecture: AMD64
@oubidar-Abderrahim
Copy link
Member

Thank you for reporting this, we'll take a look into it shortly

@oubidar-Abderrahim
Copy link
Member

Hi, when I try to reproduce the issue, the build finishes successfully with [WARNING] The requested profile "native-test" could not be activated because it does not exist.
I checked your repo and I don't see the native plugin in the pom.xml nor a branch that has native support enabled in it

@DarkAtra
Copy link
Author

DarkAtra commented Aug 15, 2023

Hi, when I try to reproduce the issue, the build finishes successfully with [WARNING] The requested profile "native-test" could not be activated because it does not exist. I checked your repo and I don't see the native plugin in the pom.xml nor a branch that has native support enabled in it

sorry it's nativeTest instead of native-test. E.g.:

./mvnw -B -ntp -PnativeTest clean verify

It comes from the spring boot parent.

@DarkAtra
Copy link
Author

DarkAtra commented Sep 7, 2023

@oubidar-Abderrahim have you had a chance to look at this yet?

@oubidar-Abderrahim
Copy link
Member

I managed to reproduce the issue, this is tracked internally at GR 48812

@DarkAtra
Copy link
Author

hey @oubidar-Abderrahim, is there any workaround for this issue that you could recommend for the time being? (besides sticking with an older version of graalvm)

@oubidar-Abderrahim oubidar-Abderrahim changed the title Native builds fail with most recent GraalVM 17 versions [GR-48812] Native builds fail with most recent GraalVM 17 versions Apr 22, 2024
@DarkAtra
Copy link
Author

DarkAtra commented Jun 30, 2024

hey @loicottet, is there any workaround for this issue for the time being? this issue is getting more and more annoying and blocks me from releasing a new version of my project. I'd highly appreciate any hint to why this error occurs and what i could do to prevent it from happening for now (even if it is super hacky).

This error now also started to happen in graalvm-ce-java17-darwin/22.3.2/x64/graalvm-ce-java17-22.3.2 (the one that previously worked): https://github.com/DarkAtra/v-rising-discord-bot/actions/runs/9731900584/job/26856921079#step:4:350

There have been quite a few changes up to that build (see here). I was unable to narrow down why this issue now occurrs here as well. Nothing related to kord or graalvm has really changed as the whole point of that branch was to update the underlying database to the most recent version. Somehow that also affected the native build.

@vjovanov
Copy link
Member

vjovanov commented Jul 2, 2024

Hi @DarkAtra, thank you for bringing this up.

The workaround for this issue is to add classes that show up in the second line of the error message to reflection metadata. In the error message above that would be dev.kord.common.entity.optional.Optional$Missing$Companion.

I applied the following diff to the provided project and the image was built successfully:

diff --git i/src/main/kotlin/de/darkatra/vrising/discord/BotRuntimeHints.kt w/src/main/kotlin/de/darkatra/vrising/discord/BotRuntimeHints.kt
index d775400b0d..3030e26bba 100644
--- i/src/main/kotlin/de/darkatra/vrising/discord/BotRuntimeHints.kt
+++ w/src/main/kotlin/de/darkatra/vrising/discord/BotRuntimeHints.kt
@@ -77,7 +77,9 @@ class BotRuntimeHints : RuntimeHintsRegistrar {
             ThreadMemberData::class.java,
             UserData::class.java,
             VoiceStateData::class.java,
-            WebhookData::class.java
+            WebhookData::class.java,
+            dev.kord.common.entity.optional.Optional.Null.Companion::class.java,
+            dev.kord.common.entity.optional.Optional.Missing.Companion::class.java
         )
 
         hints.reflection()

DarkAtra added a commit to DarkAtra/v-rising-discord-bot that referenced this issue Jul 2, 2024
DarkAtra added a commit to DarkAtra/v-rising-discord-bot that referenced this issue Jul 2, 2024
@DarkAtra
Copy link
Author

DarkAtra commented Jul 2, 2024

Hi @DarkAtra, thank you for bringing this up.

The workaround for this issue is to add classes that show up in the second line of the error message to reflection metadata. In the error message above that would be dev.kord.common.entity.optional.Optional$Missing$Companion.

I applied the following diff to the provided project and the image was built successfully:

diff --git i/src/main/kotlin/de/darkatra/vrising/discord/BotRuntimeHints.kt w/src/main/kotlin/de/darkatra/vrising/discord/BotRuntimeHints.kt
index d775400b0d..3030e26bba 100644
--- i/src/main/kotlin/de/darkatra/vrising/discord/BotRuntimeHints.kt
+++ w/src/main/kotlin/de/darkatra/vrising/discord/BotRuntimeHints.kt
@@ -77,7 +77,9 @@ class BotRuntimeHints : RuntimeHintsRegistrar {
             ThreadMemberData::class.java,
             UserData::class.java,
             VoiceStateData::class.java,
-            WebhookData::class.java
+            WebhookData::class.java,
+            dev.kord.common.entity.optional.Optional.Null.Companion::class.java,
+            dev.kord.common.entity.optional.Optional.Missing.Companion::class.java
         )
 
         hints.reflection()

Thanks for your response. The suggested fix works.

DarkAtra added a commit to DarkAtra/v-rising-discord-bot that referenced this issue Jul 3, 2024
DarkAtra added a commit to DarkAtra/v-rising-discord-bot that referenced this issue Jul 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants