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

Cannot configure reflection for graalvm with java when method has primitive types #980

Open
davireis opened this issue Apr 4, 2024 · 0 comments

Comments

@davireis
Copy link

davireis commented Apr 4, 2024

Expected Behavior

As seen in https://guides.micronaut.io/latest/micronaut-graalvm-reflection-gradle-java.html, one can configure graalvm reflection through a reflect-config.json file or with a java file. The latter has the small advantage of giving some IDE help on typing the classes. Other than that, I would expect the two formats below to be strictly equivalent:

The json:

[
    {
        "name": "org.flywaydb.database.postgresql.PostgreSQLConfigurationExtension",
        "methods": [
            {
                "name": "setTransactionalLock",
                "parameterTypes": [
                    "boolean"
                ]
            }
        ]
    }
]

The java:

import io.micronaut.core.annotation.ReflectionConfig;
import org.flywaydb.database.postgresql.PostgreSQLConfigurationExtension;

@ReflectionConfig(
        type = PostgreSQLConfigurationExtension.class,
        methods = {
                @ReflectionConfig.ReflectiveMethodConfig(name = "setTransactionalLock", parameterTypes = { boolean.class })
        }
)

Actual Behaviour

For methods that take no parameters or that take a class as a parameter, the two forms are strictly equivalent, and my binary runs just fine. However, for a method that takes a boolean as a parameter, it seems the reflection is not registered with Graalvm when using a Java-based configuration, and I receive the error below. When using a JSON config, everything works just fine.

 [main] io.micronaut.runtime.Micronaut -  Error starting Micronaut server: Bean definition [javax.sql.DataSource] could not be loaded: The program tried to reflectively invoke method public void org.flywaydb.database.postgresql.PostgreSQLConfigurationExtension.setTransactionalLock(boolean) without it being registered for runtime reflection. Add public void org.flywaydb.database.postgresql.PostgreSQLConfigurationExtension.setTransactionalLock(boolean) to the reflection metadata to solve this problem. See https://www.graalvm.org/latest/reference-manual/native-image/metadata/#reflection for help.
      > [svcs-tracker-dpl-bb6d966bc-nl6gc svcs-tracker-cnt] io.micronaut.context.exceptions.BeanInstantiationException: Bean definition [javax.sql.DataSource] could not be loaded: The program tried to reflectively invoke method public void org.flywaydb.database.postgresql.PostgreSQLConfigurationExtension.setTransactionalLock(boolean) without it being registered for runtime reflection. Add public void org.flywaydb.database.postgresql.PostgreSQLConfigurationExtension.setTransactionalLock(boolean) to the reflection metadata to solve this problem. See https://www.graalvm.org/latest/reference-manual/native-image/metadata/#reflection for help.

Steps To Reproduce

  1. In a micronaut project that uses reflection on initialization:
  2. ./gradlew --no-configuration-cache nativeRun

Environment Information

$ systeminfo /fo csv | ConvertFrom-Csv | select OS*, System*, Hotfix* | Format-List
OS Name : Microsoft Windows 11 Pro
OS Version : 10.0.22631 N/A Build 22631
OS Manufacturer : Microsoft Corporation
OS Configuration : Standalone Workstation
OS Build Type : Multiprocessor Free
System Boot Time : 15/03/2024, 02:48:47
System Manufacturer : CORSAIR
System Model : CORSAIR VENGEANCE i8100
System Type : x64-based PC
System Directory : C:\Windows\system32
System Locale : en-us;English (United States)
Hotfix(s) : 7 Hotfix(s) Installed.,[01]: KB5034467,[02]: KB5012170,[03]: KB5026039,[04]: KB5027397,[05]: KB5035942,[06]: KB5035967,[07]: KB5036398

$ java -version:
openjdk version "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)

Example Application

No response

Version

4.3.7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants