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.
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.
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.
@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.
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.
Most helpful comment
@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 thatNoClassDefFoundErrorcan occur.