Skip to content

GraalVM native image build fails with AsyncResultExtensions classes found in image heap (1.61.0 / 1.61.1) #11236

@Ricard-Kollcaku

Description

@Ricard-Kollcaku

Tracer Version(s)

1.61.1

Java Version(s)

Oracle GraalVM 25.0.3

JVM Vendor

Oracle GraalVM

Bug Report

When building a GraalVM native image using dd-java-agent 1.61.0 or 1.61.1 with a Spring Boot 4 application that uses a Spring Kafka listener, the native image compilation fails with two fatal UnsupportedFeatureException errors.

Both errors are for inner classes of datadog.trace.bootstrap.instrumentation.java.concurrent.AsyncResultExtensions that are found in the image heap but are marked for runtime initialization.

Environment:

Component Version
dd-java-agent 1.61.0 and 1.61.1 (both fail)
Paketo Datadog buildpack 6.9.0 (agent 1.61.0) / 6.9.2 (agent 1.61.1)
GraalVM (Oracle) Java 25 via Paketo paketobuildpacks/oracle:4.5.1
Native image buildpack paketo-buildpacks/native-image:5.18.2
Spring Boot 4.0.4
Spring Kafka 4.0.4
Builder paketobuildpacks/builder-noble-java-tiny

Fatal error 1:

Fatal error: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException:
An object of type 'datadog.trace.bootstrap.instrumentation.java.concurrent.AsyncResultExtensions$CompletableAsyncResultExtension'
was found in the image heap. This type, however, is marked for initialization at image run time
for the following reason: classes are initialized at run time by default.

This is not allowed for correctness reasons: All objects that are stored in the image heap must be initialized at build time.

Object was reached by
  indexing into array java.lang.Object[]@5baa4549
  reading field java.util.concurrent.CopyOnWriteArrayList.array of constant
    java.util.concurrent.CopyOnWriteArrayList@2d902351: [datadog.trace.bootstrap.instrumentation.java.concurrent.AsyncResultExtensions$C...
  scanning root java.util.concurrent.CopyOnWriteArrayList@2d902351 embedded in
    datadog.trace.bootstrap.instrumentation.java.concurrent.AsyncResultExtensions.access$000(AsyncResultExtensions.java:15)

Fatal error 2:

Fatal error: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException:
An object of type 'datadog.trace.bootstrap.instrumentation.java.concurrent.AsyncResultExtensions$1'
was found in the image heap. This type, however, is marked for initialization at image run time
for the following reason: classes are initialized at run time by default.

Object was reached by
  scanning root datadog.trace.bootstrap.instrumentation.java.concurrent.AsyncResultExtensions$1@21c0dd65 embedded in
    datadog.trace.bootstrap.instrumentation.java.concurrent.AsyncResultExtensions.wrapAsyncResult(AsyncResultExtensions.java:39)
  parsing method datadog.trace.bootstrap.instrumentation.java.concurrent.AsyncResultExtensions.wrapAsyncResult(AsyncResultExtensions.java:39)
  reachable via the parsing context:
    at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:119)
    at org.springframework.kafka.listener.adapter.HandlerAdapter.invoke(HandlerAdapter.java:80)

Expected Behavior

Native image build completes successfully. The AsyncResultExtensions class and its inner classes should either be marked for --initialize-at-build-time in the agent's own native image configuration, or instantiation should not happen at build time.

Reproduction Code

Spring Boot 4 @KafkaListener method (the call stack in the error points directly to this path):

@KafkaListener(topics = "${sevensenders.kafka.consumer.topic}")
public void onMessage(ConsumerRecord<String, String> record, Acknowledgment acknowledgment) {
    // handler body
}

build.gradle (Paketo bootBuildImage config):

bootBuildImage {
    builder = "paketobuildpacks/builder-noble-java-tiny"
    buildpacks = [
        'docker.io/paketobuildpacks/oracle',
        'docker.io/paketobuildpacks/datadog:6.9.2',   // or 6.9.0 — both fail
        'urn:cnb:builder:paketo-buildpacks/java-native-image',
    ]
    environment = [
        "BP_NATIVE_IMAGE"   : "true",
        "BP_DATADOG_ENABLED": "true",
    ]
}

Working version: docker.io/paketobuildpacks/datadog:6.4.0dd-java-agent 1.57.0 builds successfully with the same application and GraalVM configuration.

The first failing version has not been bisected exactly — 1.57.0 works, 1.61.0 and 1.61.1 both fail.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bugBug report and fix

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions