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

NoClassDefFoundError: kotlin/reflect/KParameter #656

Closed
dsyer opened this issue Sep 4, 2018 · 4 comments
Closed

NoClassDefFoundError: kotlin/reflect/KParameter #656

dsyer opened this issue Sep 4, 2018 · 4 comments

Comments

@dsyer
Copy link

dsyer commented Sep 4, 2018

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.

@dougxc
Copy link
Member

dougxc commented Sep 4, 2018

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.

@dougxc dougxc self-assigned this Sep 4, 2018
@dsyer
Copy link
Author

dsyer commented Sep 4, 2018

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.

@dougxc
Copy link
Member

dougxc commented Sep 4, 2018

@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.

@cstancu
Copy link
Member

cstancu commented Feb 7, 2019

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.

@cstancu cstancu closed this as completed Feb 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants