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

Groovy compiler error: exception in phase 'class generation' in source unit #771

Closed
boris-petrov opened this issue Nov 28, 2018 · 14 comments
Assignees
Labels
Milestone

Comments

@boris-petrov
Copy link

I've been using groovy-eclipse fine. Today I updated the Groovy compiler from 2.4.x to 2.5.4 and I started getting this error. It doesn't happen when I build my project with Gradle (which also has 2.5.4). I'm using Eclipse Version: 2018-09 (4.9.0) and the snapshot build of groovy-eclipse. Any ideas?

@eric-milles
Copy link
Member

@boris-petrov You'll need to provide more information to understand this error. Is it possible to provide the project that you are trying to compile? Can you reduce the project to a minimal number of files that still exhibit the problem?

@boris-petrov
Copy link
Author

@eric-milles - thanks for the response. I cannot provide the project but I will try to reproduce it in a minimal example. This will happen next week as I have my hands full right now. I'll write here with an example. Thanks!

@boris-petrov
Copy link
Author

Just a quick note - I think this has something to do with org.spockframework:spock-core:1.2-groovy-2.5. When using org.spockframework:spock-core:1.2-groovy-2.4 and Groovy 2.4.x it works fine.

@boris-petrov
Copy link
Author

I cannot seem to do anything meaningful. I try removing a bunch of stuff, modifying things, this error doesn't go away. It changes between files, but is always there even if I remove half our code. There's also another very strange error: Groovy:The method public volatile java.lang.Object next() { ... } duplicates another method of the same signature
Also no idea where this comes from and why... only happens on 2.5. Not sure how to proceed from here...?

@eric-milles
Copy link
Member

Can you reduce the project to something shareable that exhibits the error or an error? When compiling the whole project, often the first source unit receives the error for the entire compilation batch. This is likely why you are seeing the error move around when you delete stuff.

Have you tried opening the Groovy Event Console, cleaning and rebuilding? There may be more information in there is terms of a compilation problem.

@boris-petrov
Copy link
Author

I'll try those things tomorrow. Thanks for the support!

@boris-petrov
Copy link
Author

So when I remove all of our Spock tests, the project compiles fine. When I just have one empty Spock test like:

package somepackage

import spock.lang.Specification

class SomeSpec extends Specification {
}

Then I get that error. This is with org.spockframework:spock-core:1.2-groovy-2.5 as I said. I think that should be enough for reproduction. Please tell me if I can do something more.

@eric-milles
Copy link
Member

I'm not having any problem compiling with spock-core-1.2-groovy-2.5. Can you send a small project that demonstrates the error? I can't tell what other settings and dependencies you have that may be part of the problem.

@boris-petrov
Copy link
Author

OK, I'll try to create a full reproduction next week.

@boris-petrov
Copy link
Author

OK, here you go. Checkout the repo, run gradle eclipse, open the project in Eclipse. Clean/rebuild the project - you'll see the error. Be sure to be using the 2.5 compiler. It took me quite a while to do this, you owe me a beer! :)

@eric-milles
Copy link
Member

@boris-petrov Is this the error you are seeing?

BUG! exception in phase 'class generation' in source unit 'C:\Users\U0076777\pde-workspaceg\eclipse-space\backend1\src\seed\groovy\foobar\Util.groovy' foobar.BaseObjectCodecProvider
	at org.codehaus.groovy.control.CompilationUnit$20.getClassNode(CompilationUnit.java:916)
	...
Caused by: java.lang.ClassNotFoundException: foobar.BaseObjectCodecProvider
	at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:466)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:566)
	at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:762)
	at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:637)
	at org.codehaus.groovy.control.CompilationUnit$20.getClassNode(CompilationUnit.java:913)
	... 22 more

@eric-milles
Copy link
Member

In order to resolve the assignment within this method, the compiler is trying to find the common super class of CodecProvider and BaseObjectCodecProvider. It fails in finding the ClassNode for BaseObjectCodecProvider for some reason. If you need to work around this for now, you can add a typecast in front of BaseObjectCodecProvider so that there is no need to compute a common super class.

	static void getMongoCollection(CodecProvider codecProvider = null) {
		codecProvider = codecProvider ?: new BaseObjectCodecProvider()
	}

@eric-milles
Copy link
Member

Ready to test

@boris-petrov
Copy link
Author

@eric-milles - thank you for the support and fix! Seems fine now. I'll close the issue. Thanks again!

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