Skip to content

NoClassDefFoundError: kotlin/reflect/KParameter #656

Closed

Description

@dsyer

This is new with image generation for a minimal Spring Boot app in rc6:

fatal error: java.lang.NoClassDefFoundError: kotlin/reflect/KParameter
	at java.lang.Class.getDeclaredMethods0(Native Method)
	at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
	at java.lang.Class.getDeclaredMethods(Class.java:1975)
	at jdk.vm.ci.hotspot.HotSpotResolvedJavaMethodImpl.toJava(HotSpotResolvedJavaMethodImpl.java:611)
	at jdk.vm.ci.hotspot.HotSpotResolvedJavaMethodImpl.getAnnotation(HotSpotResolvedJavaMethodImpl.java:537)
	at com.oracle.svm.hosted.cenum.CEnumCallWrapperSubstitutionProcessor.lookup(CEnumCallWrapperSubstitutionProcessor.java:51)
...

Source code and README: https://github.com/dsyer/spring-boot-aot.

Activity

  1. dougxc commented on Sep 4, 2018

    @dougxc
    Member

    Hi @dsyer , this is due to a fix for a bug in JVMCI. The problem is that to get the annotation for a ResolvedJavaMethod the HotSpot JVMCI implementation first converts it to a java.lang.reflect.Method and calls getAnnotation on it. The conversion can fail if any other method declared in the same class has a type in its signature that cannot be resolved (and thus raises the NoClassDefFoundError). The solution is to modify the class path such that it includes the missing type. In your case, you need to add the jar or directory to the native-image class path that contains kotlin/reflect/KParameter.class.

    I am currently pushing a change that will provide a clearer error message for this situation.

  2. self-assigned this
    on Sep 4, 2018
  3. dsyer commented on Sep 4, 2018

    @dsyer
    Author

    I can't say I like that solution. It's a workaround right? I shouldn't have to put things on the classpath just to build a native image? It bloats the image and possibly even changes the behaviour of the app at runtime.

    I added a dummy KParameter (empty class) and it works now (on master of that sample project). This really doesn't feel like a solution anyone will be happy with.

  4. dougxc commented on Sep 4, 2018

    @dougxc
    Member

    @christianwimmer @cstancu this is a reasonable objection raised by @dsyer . I think all calls to getAnnotation() (and friends) in the native image building process should now take into account that NoClassDefFoundError can occur.

  5. cstancu commented on Feb 7, 2019

    @cstancu
    Member

    This issue is fixed as of RC12. NoClassDefFoundErrors that occur as result of getAnnotation() and other reflective calls are now swallowed by the native image builder and, where appropriate, the proper error is reported at run time when the --allow-incomplete-classpath option is used.

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

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions