Skip to content

[GR-73296][Native Image] ClassCastException: HostedInterface cannot be cast to HostedInstanceClassΒ #12914

@codesimplicity

Description

@codesimplicity

Describe the Issue

We have multiple Spring Boot applications which we build via the Gradle task bootBuildImage using paketobuildpacks/oracle:latest (GraalVM 25).
We also apply a PGO profile which we regularly generate for each application.

When trying to update to Spring Boot 3.5.10, this build reproducibly fails for one of our applications while it works for others.

Details:

  • fails with PGO profile generated with Spring Boot 3.5.9
  • works with PGO profile generated with Spring Boot 3.5.10
  • works without PGO profile

The builds run on GitHub action runners. I can reproduce it on a system with the details in "Operating System and Version".

My assumption would be that any PGO profile can be used in a build. The only downside may be optimising for the wrong things. That's at least how I read the documentation.

Using the latest version of GraalVM can resolve many issues.

GraalVM Version

paketobuildpacks/oracle:latest (GraalVM 25)

Operating System and Version

Linux gh-action-runner 5.14.0-611.13.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Dec 12 11:55:11 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux

Build Command

./gradlew build bootBuildImage -PimageName=some-application:TEMP-PR_157

config in build.gradle:

def iprofFile = "service.iprof"
bootBuildImage {
    def nativeImageBuildArguments = "-J-Xmx20G -H:IncludeLocales=de,en"
    if (project.hasProperty('buildInstrumentedImage')) {
        nativeImageBuildArguments += project.buildInstrumentedImage ? " --pgo-instrument " : ""
    } else if (new File(iprofFile).exists()) {
        nativeImageBuildArguments += " --pgo=/workspace/BOOT-INF/classes/${iprofFile}"
    }

    imageName = project.hasProperty("imageName") ? project.ext.imageName : null
    // default misses 'libstdc++.so.6' and may also not work with Kubernetes mounts
    // see https://docs.spring.io/spring-boot/how-to/native-image/developing-your-first-application.html#howto.native-image.developing-your-first-application.buildpacks
    runImage = 'paketobuildpacks/ubuntu-noble-run'
    environment = [
            "BP_JVM_VERSION": "25", // GraalVM 25
            "BP_NATIVE_IMAGE_BUILD_ARGUMENTS": "$nativeImageBuildArguments",
    ]

    //    Use Oracle GraalVM to support PGO profiles
    buildpacks = [
            "docker://test-registry/dockerhub/paketobuildpacks/oracle:latest", "urn:cnb:builder:paketo-buildpacks/java-native-image"
    ]
}

Expected Behavior

Native image can be built with PGO profile applied.

Actual Behavior

Build fails with ClassCastException

Steps to Reproduce

Failing case:

  1. create PGO profile with Spring Boot 3.5.9
  2. try to build native image with Spring Boot 3.5.10 using the PGO profile
  3. build fails

Successful case:

  1. create PGO profile with Spring Boot 3.5.10
  2. try to build native image with Spring Boot 3.5.10 using the PGO profile
  3. build succeeds

I have attached a diff of the types referenced in the PGO profiles (removed application specific classes): diff-iprof-types.txt

Additional Context

I have not been able to access the generated error report (mentioned in the log output: /layers/paketo-buildpacks_native-image/native-image/svm_err_b_20260129T171259.740_pid408.md).

I would need advice how to extract that from such a Paketo build - didn't find anything in the Docker volumes.

Build Log Output and Error Messages

native-image-creator-output.log

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions