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

Compilation error where classpath should exclude code path #523

Closed
dsyer opened this issue Jul 5, 2018 · 4 comments
Closed

Compilation error where classpath should exclude code path #523

dsyer opened this issue Jul 5, 2018 · 4 comments
Assignees

Comments

@dsyer
Copy link

dsyer commented Jul 5, 2018

This one is a bit strange because I can't reproduce it with a simple sample. If you try to compile a simple empty Spring Boot app it falls over like this:

Build on Server(pid: 26395, port: 46211)
   classlist:   2,385.00 ms
       (cap):     654.30 ms
       setup:     941.67 ms
    analysis:   9,080.94 ms
error: Bytecode parsing error: java.lang.NoClassDefFoundError
Detailed message:
Error: Bytecode parsing error: java.lang.NoClassDefFoundError
Trace: 
	at parsing org.springframework.boot.BeanDefinitionLoader.load(BeanDefinitionLoader.java:166)
Call path from entry point to org.springframework.boot.BeanDefinitionLoader.load(BeanDefinitionLoader$GroovyBeanDefinitionSource): 
	at org.springframework.boot.BeanDefinitionLoader.load(BeanDefinitionLoader.java:165)
	at org.springframework.boot.BeanDefinitionLoader.load(BeanDefinitionLoader.java:155)
	at org.springframework.boot.BeanDefinitionLoader.load(BeanDefinitionLoader.java:135)
	at org.springframework.boot.BeanDefinitionLoader.load(BeanDefinitionLoader.java:127)
	at org.springframework.boot.SpringApplication.load(SpringApplication.java:704)
	at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:393)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:328)
	at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:137)
	at com.example.demo.DemoApplication.main(DemoApplication.java:24)
	at com.oracle.svm.reflect.proxies.Proxy_84_DemoApplication_main.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.oracle.svm.core.JavaMainWrapper.run(JavaMainWrapper.java:173)
	at com.oracle.svm.core.code.CEntryPointCallStubs.com_002eoracle_002esvm_002ecore_002eJavaMainWrapper_002erun_0028int_002corg_002egraalvm_002enativeimage_002ec_002etype_002eCCharPointerPointer_0029(generated:0)
Original exception that caused the problem: java.lang.NoClassDefFoundError
	at jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.lookupType(HotSpotJVMCIRuntime.java:387)
	at jdk.vm.ci.hotspot.HotSpotUnresolvedJavaType.resolve(HotSpotUnresolvedJavaType.java:91)
	at com.oracle.graal.pointsto.infrastructure.WrappedSignature.getReturnType(WrappedSignature.java:55)
	at com.oracle.graal.pointsto.flow.MethodFlowsGraph.<init>(MethodFlowsGraph.java:113)
	at com.oracle.graal.pointsto.flow.MethodTypeFlow.<init>(MethodTypeFlow.java:75)
	at com.oracle.graal.pointsto.meta.AnalysisMethod.<init>(AnalysisMethod.java:127)
	at com.oracle.graal.pointsto.meta.AnalysisUniverse.createMethod(AnalysisUniverse.java:399)
	at com.oracle.graal.pointsto.meta.AnalysisUniverse.lookupAllowUnresolved(AnalysisUniverse.java:387)
	at com.oracle.graal.pointsto.infrastructure.WrappedConstantPool.lookupMethod(WrappedConstantPool.java:78)
	at org.graalvm.compiler.java.BytecodeParser.lookupMethod(BytecodeParser.java:3900)
	at org.graalvm.compiler.java.BytecodeParser.genInvokeInterface(BytecodeParser.java:1454)
	at org.graalvm.compiler.java.BytecodeParser.processBytecode(BytecodeParser.java:4813)
	at org.graalvm.compiler.java.BytecodeParser.iterateBytecodesForBlock(BytecodeParser.java:3114)
	at org.graalvm.compiler.java.BytecodeParser.processBlock(BytecodeParser.java:2923)
	at org.graalvm.compiler.java.BytecodeParser.build(BytecodeParser.java:888)
	at org.graalvm.compiler.java.BytecodeParser.buildRootMethod(BytecodeParser.java:782)
	at org.graalvm.compiler.java.GraphBuilderPhase$Instance.run(GraphBuilderPhase.java:95)
	at org.graalvm.compiler.phases.Phase.run(Phase.java:49)
	at org.graalvm.compiler.phases.BasePhase.apply(BasePhase.java:197)
	at org.graalvm.compiler.phases.Phase.apply(Phase.java:42)
	at org.graalvm.compiler.phases.Phase.apply(Phase.java:38)
	at com.oracle.graal.pointsto.flow.MethodTypeFlowBuilder.parse(MethodTypeFlowBuilder.java:196)
	at com.oracle.graal.pointsto.flow.MethodTypeFlowBuilder.apply(MethodTypeFlowBuilder.java:315)
	at com.oracle.graal.pointsto.flow.MethodTypeFlow.doParse(MethodTypeFlow.java:310)
	at com.oracle.graal.pointsto.flow.MethodTypeFlow.ensureParsed(MethodTypeFlow.java:300)
	at com.oracle.graal.pointsto.flow.MethodTypeFlow.addContext(MethodTypeFlow.java:107)
	at com.oracle.graal.pointsto.flow.SpecialInvokeTypeFlow.onObservedUpdate(InvokeTypeFlow.java:421)
	at com.oracle.graal.pointsto.flow.TypeFlow.notifyObservers(TypeFlow.java:347)
	at com.oracle.graal.pointsto.flow.TypeFlow.update(TypeFlow.java:389)
	at com.oracle.graal.pointsto.BigBang$2.run(BigBang.java:500)
	at com.oracle.graal.pointsto.util.CompletionExecutor.lambda$execute$0(CompletionExecutor.java:174)
	at java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1402)
	at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
	at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
	at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
	at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Caused by: java.lang.ClassNotFoundException: groovy.lang.Closure
	at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	at jdk.vm.ci.hotspot.CompilerToVM.lookupType(Native Method)
	at jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.lookupType(HotSpotJVMCIRuntime.java:379)
	... 35 more

Error: Processing image build request failed

The missing class is not actually needed at runtime, but we can't compile so we never get to prove it. The offending code in Spring Boot is here I think. Notice that the interface that depends on groovy.lang.Closure is never used if isGroovyPresent() is false.

I tried to reproduce the problem with a simpler program and couldn't, so I'm out of ideas now. Maybe someone else can spot the different between the above code and this (which compiles and runs):

public class Missings {

	public static void main(String[] args) {
		new Missings().run(args);
	}

	private void run(String[] args) {
		Class<?> source = args.length > 0 ? ClassUtils.resolveClassName(args[0], null)
				: this.getClass();
		System.err.println(source + " " + isGroovyPresent());
		if (isGroovyPresent()
				&& GroovyBeanDefinitionSource.class.isAssignableFrom(source)) {
			GroovyBeanDefinitionSource loader = BeanUtils.instantiateClass(source,
					GroovyBeanDefinitionSource.class);
			load(loader);
			throw new IllegalStateException(
					"Not expecting to find GroovyBeanDefinitionSource");
		}
	}

	private void load(GroovyBeanDefinitionSource loader) {
		System.err.println(loader);
	}

	private boolean isGroovyPresent() {
		return ClassUtils.isPresent("groovy.lang.MetaClass", null);
	}

	@FunctionalInterface
	protected interface GroovyBeanDefinitionSource {

		Closure<?> getBeans();

	}
}
@cstancu cstancu self-assigned this Jul 5, 2018
@cstancu
Copy link
Member

cstancu commented Jul 5, 2018

@dsyer cannot spot the difference but looking at the stack trace I can see that BytecodeParser.genInvokeInterface should be intercepted and the type resolution error should be pushed at runtime when --report-unsupported-elements-at-runtime is used. The type resolution error seems to happen when WrappedSignature.getReturnType() is called for the target method of an invoke interface.

@mageddo
Copy link

mageddo commented Jan 25, 2019

Got same issue trying to build this spring boot app

./gradlew clean build nativeImage
Picked up JAVA_TOOL_OPTIONS:  -Dawt.useSystemAAFontSettings=on -Dswing.aatext=true
To honour the JVM settings for this build a new JVM will be forked. Please consider using the daemon: https://docs.gradle.org/5.0/userguide/gradle_daemon.html.
Daemon will be stopped at the end of the build stopping after processing

> Task :nativeImage
Shutdown Server(pid: 9445, port: 44565)
Build on Server(pid: 10936, port: 46019)*
[graal:10936]    classlist:   2,633.69 ms
[graal:10936]        (cap):     632.25 ms
[graal:10936]        setup:   1,353.65 ms
[graal:10936]     analysis:   7,762.18 ms
fatal error: java.lang.NoClassDefFoundError
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
        at java.util.concurrent.ForkJoinTask.getThrowableException(ForkJoinTask.java:598)
        at java.util.concurrent.ForkJoinTask.get(ForkJoinTask.java:1005)
        at com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:420)
        at com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:278)
        at com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:396)
        at com.oracle.svm.hosted.server.NativeImageBuildServer.executeCompilation(NativeImageBuildServer.java:391)
        at com.oracle.svm.hosted.server.NativeImageBuildServer.lambda$processCommand$8(NativeImageBuildServer.java:328)
        at com.oracle.svm.hosted.server.NativeImageBuildServer.withJVMContext(NativeImageBuildServer.java:409)
        at com.oracle.svm.hosted.server.NativeImageBuildServer.processCommand(NativeImageBuildServer.java:325)
        at com.oracle.svm.hosted.server.NativeImageBuildServer.processRequest(NativeImageBuildServer.java:269)
        at com.oracle.svm.hosted.server.NativeImageBuildServer.lambda$serve$7(NativeImageBuildServer.java:229)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NoClassDefFoundError: groovy/lang/Closure
        at java.lang.Class.getDeclaredMethods0(Native Method)
        at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
        at java.lang.Class.getDeclaredMethods(Class.java:1975)
        at com.oracle.svm.hosted.ClassInitializationFeature.declaresDefaultMethods(ClassInitializationFeature.java:281)
        at com.oracle.svm.hosted.ClassInitializationFeature.declaresDefaultMethods(ClassInitializationFeature.java:273)
        at com.oracle.svm.hosted.ClassInitializationFeature.hasDefaultMethods(ClassInitializationFeature.java:269)
        at com.oracle.svm.hosted.ClassInitializationFeature.buildClassInitializationInfo(ClassInitializationFeature.java:256)
        at com.oracle.svm.hosted.ClassInitializationFeature.duringAnalysis(ClassInitializationFeature.java:198)
        at com.oracle.svm.hosted.NativeImageGenerator.lambda$doRun$7(NativeImageGenerator.java:713)
        at com.oracle.svm.hosted.FeatureHandler.forEachFeature(FeatureHandler.java:63)
        at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:713)
        at com.oracle.svm.hosted.NativeImageGenerator.lambda$run$0(NativeImageGenerator.java:403)
        at java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1386)
        at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
        at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
        at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
        at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Caused by: java.lang.ClassNotFoundException: groovy.lang.Closure
        at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        ... 17 more

@cstancu
Copy link
Member

cstancu commented Jan 28, 2019

@mageddo your trace is different from the originally reported issue, but I think it was the same underlying problem. This issue was fixed recently (specifically in dd0bae3). The fix will be available in 1.0.0-rc12 coming out next week. In the meantime you can build from master.

@dsyer the original issue should be fixed too.

@cstancu
Copy link
Member

cstancu commented Feb 4, 2019

I will close this. Please reopen if it still occurs.

@cstancu cstancu closed this as completed Feb 4, 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

3 participants