Native Quarkus appears to be ignoring lines of code that contain objects from classes configured for reflection

115 views Asked by At

In my quarkus project, I depend on a third-party project. When I run the application in dev mode or generate a jar file, everything goes fine. But not in Native mode.

When I generate the native, this error happens:

java.lang.RuntimeException: java.lang.RuntimeException: Unable to create instance of class com.x.x.x.x.Issue. Registering an InstanceCreator or a TypeAdapter for this type, or adding a no-args constructor may fix this problem.

Caused by: java.lang.RuntimeException: java.lang.RuntimeException: Unable to create instance of class com.x.x.x.x.issue.Issue. Registering an InstanceCreator or a TypeAdapter for this type, or adding a no-args constructor may fix this problem.
       
Caused by: java.lang.IllegalArgumentException: Type com.x.x.x.x.Issue is instantiated reflectively but was never registered. Register the type by adding "unsafeAllocated" for the type in reflect-config.json.
       at org.graalvm.nativeimage.builder/com.oracle.svm.core.graal.snippets.SubstrateAllocationSnippets.instanceHubErrorStub(SubstrateAllocationSnippets.java:315)
       at [email protected]/sun.misc.Unsafe.allocateInstance(Unsafe.java:884)

I created the following file for reflection configuration and the error during compilation was resolved:

[
  {
    "name": "com.x.x.x.x.Issue",
    "allDeclaredConstructors": true,
    "allPublicConstructors": true,
    "allDeclaredMethods": true,
    "allPublicMethods": true,
    "allDeclaredFields": true,
    "allPublicFields": true,
    "unsafeAllocated": true
  }
]

But when I run the application natively, it doesn't seem to be performing any action on the Issue class objects. Only Log.info("STARTED ACCEPT") and Log.info("STARTED ACCEPT") are written to the log file, other lines seem to be ignored, nothing happens, not even an error.

public void accept(final ScheduledExecution scheduledExecution) {
            Log.info("STARTED ACCEPT");
            final List<Issue> issues = retrieveIssues();
            Log.info("ISSUES :" + issues);
            Log.info("FIRST ISSUE Key: " + issues.get(0).getKey());
            Log.info("FINISHED ACCEPT");
}

When I run it in development mode or run the jar, all logs are written or printed correctly. Does anyone have any idea what could be happening?

1

There are 1 answers

0
Alina Yurenko On

Not sure that this is what's happening, but could it be that Native Image doesn't see and include some code. Can you try running with the tracing agent, making sure that the config produced by the agent is picked up, and see if that fixes the issue?