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

GraalVM native image fails at run time due to NoClassDefFoundError #1617

Open
AyushChaubey opened this issue Apr 19, 2024 · 3 comments
Open
Assignees
Labels
Milestone

Comments

@AyushChaubey
Copy link

I am using a third party library that uses ByteBuddy. The native image is created successfully but fails at run time with below exception -

java.lang.NoClassDefFoundError: Could not initialize class net.bytebuddy.implementation.bind.MethodDelegationBinder$AmbiguityResolver
        at net.bytebuddy.implementation.MethodDelegation.withDefaultConfiguration(MethodDelegation.java:606)

Fixes attempted:
I have used GraalVM tracing agent , followed suggestions recommended here and here. After following these suggestions, I get a different error:

Defining a class from new bytecodes at run time is not supported Class XYZ... with hash a35588c was not provided during the image build

Can you please help on how to proceed here.

Thanks

@raphw
Copy link
Owner

raphw commented Apr 20, 2024

Are you using a random naming strategy? Likely, some byte code is changed during prerun and compile?

@raphw raphw self-assigned this Apr 20, 2024
@raphw raphw added the question label Apr 20, 2024
@raphw raphw added this to the 1.14.14 milestone Apr 20, 2024
@AyushChaubey
Copy link
Author

Thanks for your reply. In the library code, name is not passed for the subclass. I added the name to the dynamic type. I still get the same error but with the name of the dynamic type when I run the native image.

Exception:
Defining a class from new bytecodes at run time is not supported. Class XYZ with hash 07e29f719685ecf5d1653a0 was not provided during the image build. Please see BuildConfiguration.md.."

Below is the code snippet from the library:

val withBinders = MethodDelegation.withDefaultConfiguration()
                .withBinders(Pipe.Binder.install(Forwarder::class.java))
                .to(MappedBatchLoaderWithContextInterceptor(original, name, meterRegistrySupplier.get()))
            ByteBuddy()
                .subclass(MappedBatchLoaderWithContext::class.java)
                .name("XYZ")
                .method(ElementMatchers.named("load"))
                .intercept(withBinders)
                .make()
                .load(javaClass.classLoader)
                .loaded
                .getDeclaredConstructor()
        }.newInstance()

@raphw
Copy link
Owner

raphw commented Apr 22, 2024

I assume that there is still some randomness and hash 07e29f719685ecf5d1653a0 is not part of the generation. Could you check the generated JSON file for what hash is recorded?

Can you check what GraalImageCode.getCurrent() returns? You could try setting org.graalvm.nativeimage.imagecode to agent what activates some sensitive defaults.

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

2 participants