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

NullPointerException preventing Groovy compilation #616

Closed
magao opened this issue Jun 28, 2018 · 19 comments
Closed

NullPointerException preventing Groovy compilation #616

magao opened this issue Jun 28, 2018 · 19 comments
Assignees
Labels
Milestone

Comments

@magao
Copy link

magao commented Jun 28, 2018

Eclipse Oxygen and Photon, JDK10 (for compilation), Groovy-Eclipse 3.0.0 (snapshot). This occurs with the latest snapshot 3.0.0.xx-201806281902-e47 (for Oxygen).

This error prevents compilation of Groovy code entirely.

On Eclipse Oxygen, the error is:

java.lang.NullPointerException
	at org.eclipse.jdt.internal.compiler.lookup.Scope.findDirectMemberType(Scope.java:1250)
	at org.eclipse.jdt.internal.compiler.lookup.Scope.getTypeOrPackage(Scope.java:3311)
	at org.eclipse.jdt.internal.compiler.lookup.Scope.getPackage(Scope.java:2916)
	at org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference.getTypeBinding(QualifiedTypeReference.java:104)
	at org.eclipse.jdt.internal.compiler.ast.TypeReference.internalResolveType(TypeReference.java:503)
	at org.eclipse.jdt.internal.compiler.ast.TypeReference.resolveType(TypeReference.java:607)
	at org.eclipse.jdt.internal.compiler.ast.TypeReference.resolveType(TypeReference.java:603)
	at org.eclipse.jdt.internal.compiler.ast.TypeReference.resolveType(TypeReference.java:599)
	at org.eclipse.jdt.internal.compiler.ast.Annotation.resolveType(Annotation.java:813)
	at org.eclipse.jdt.internal.compiler.ast.ASTNode.resolveAnnotations(ASTNode.java:865)
	at org.eclipse.jdt.internal.compiler.ast.ASTNode.resolveAnnotations(ASTNode.java:724)
	at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.getAnnotationTagBits(SourceTypeBinding.java:1025)
	at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.retrieveAnnotationHolder(SourceTypeBinding.java:2355)
	at org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding.retrieveAnnotations(ReferenceBinding.java:1724)
	at org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding.getAnnotations(ReferenceBinding.java:997)
	at org.codehaus.jdt.groovy.internal.compiler.ast.GroovyClassScope$TraitHelper.isTrait(GroovyClassScope.java:525)
	at org.codehaus.jdt.groovy.internal.compiler.ast.GroovyClassScope$TraitHelper.access$1(GroovyClassScope.java:518)
	at org.codehaus.jdt.groovy.internal.compiler.ast.GroovyClassScope.augmentMethodBindings(GroovyClassScope.java:168)
	at org.eclipse.jdt.internal.compiler.lookup.ClassScope.buildMethods(ClassScope.java:387)
	at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.initializeForStaticImports(SourceTypeBinding.java:1390)
	at org.eclipse.jdt.internal.compiler.lookup.Scope.findField(Scope.java:1424)
	at org.eclipse.jdt.internal.compiler.lookup.Scope.findField(Scope.java:1328)
	at org.eclipse.jdt.internal.compiler.lookup.Scope.getBinding(Scope.java:2064)
	at org.eclipse.jdt.internal.compiler.lookup.BlockScope.getBinding(BlockScope.java:485)
	at org.eclipse.jdt.internal.compiler.ast.QualifiedNameReference.resolveType(QualifiedNameReference.java:999)
	at org.eclipse.jdt.internal.compiler.ast.MemberValuePair.resolveTypeExpecting(MemberValuePair.java:141)
	at org.eclipse.jdt.internal.compiler.ast.Annotation.resolveType(Annotation.java:862)
	at org.eclipse.jdt.internal.compiler.ast.ASTNode.resolveAnnotations(ASTNode.java:865)
	at org.eclipse.jdt.internal.compiler.ast.ASTNode.resolveAnnotations(ASTNode.java:724)
	at org.eclipse.jdt.internal.compiler.lookup.MethodBinding.getAnnotationTagBits(MethodBinding.java:651)
	at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.resolveTypesWithSuspendedTempErrorHandlingPolicy(SourceTypeBinding.java:1869)
	at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.resolveTypesFor(SourceTypeBinding.java:1849)
	at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.methods(SourceTypeBinding.java:1539)
	at org.codehaus.jdt.groovy.internal.compiler.ast.GroovyClassScope.buildFieldsAndMethods(GroovyClassScope.java:430)
	at org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope.buildFieldsAndMethods(CompilationUnitScope.java:98)
	at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.completeTypeBindings(LookupEnvironment.java:514)
	at org.eclipse.jdt.internal.compiler.Compiler.internalBeginToCompile(Compiler.java:873)
	at org.eclipse.jdt.internal.compiler.Compiler.beginToCompile(Compiler.java:397)
	at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:447)
	at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:429)
	at org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.compile(AbstractImageBuilder.java:396)
	at org.eclipse.jdt.internal.core.builder.BatchImageBuilder.compile(BatchImageBuilder.java:191)
	at org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.compile(AbstractImageBuilder.java:329)
	at org.eclipse.jdt.internal.core.builder.BatchImageBuilder.build(BatchImageBuilder.java:62)
	at org.eclipse.jdt.internal.core.builder.JavaBuilder.buildAll(JavaBuilder.java:256)
	at org.eclipse.jdt.internal.core.builder.JavaBuilder.build(JavaBuilder.java:180)
	at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:735)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:206)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:246)
	at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:301)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:304)
	at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:360)
	at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:383)
	at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:142)
	at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:232)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:56)

Digging into the code - org.eclipse.jdt.internal.compiler.lookup.Scope.java:

public ReferenceBinding findDirectMemberType(char[] typeName, ReferenceBinding enclosingType) {
	if ((enclosingType.tagBits & TagBits.HasNoMemberTypes) != 0)
		return null; // know it has no member types (nor inherited member types)

it looks like enclosingType must be null. I would guess the fix is:

public ReferenceBinding findDirectMemberType(char[] typeName, ReferenceBinding enclosingType) {
	if (enclosingType == null || (enclosingType.tagBits & TagBits.HasNoMemberTypes) != 0)
		return null; // know it has no member types (nor inherited member types)

but I have no idea why enclosingType would be null, so there may be a more complex fix needed.

Unfortunately I'm having trouble building Groovy-Eclipse in my environment, so I can't test this fix at the moment.

@eric-milles
Copy link
Member

Can you try running with JDK8 just to see if it is the module system stuff getting in the way? See #582

@magao
Copy link
Author

magao commented Jun 29, 2018

Sorry - I should have been clearer. Eclipse is running under JDK8 (64-bit build 152 - java.runtime.version=1.8.0_152-b16). I am compiling with JDK10 (and have no option otherwise - my current task is to get our build upgraded to JDK10).

Also just realised that more of the stack trace could be useful since it's in the JDK patch - put the full trace there.

@eric-milles
Copy link
Member

Thanks for the clarification. The modulepath is unsupported at the moment. I realize this is a big gap in Java 9+ support and have been working on it for 3.0.0. Batch and Maven compilation use a different class loading scheme and should be compatible if the target JRE is used for compilation.

@magao
Copy link
Author

magao commented Jun 29, 2018

I don't understand why you closed this, or how your last comment addresses this issue. I don't see anything that indicates this is related to modulepath.

Would my proposed null check be insufficient as a fix, and if so why?

As far as I can tell there is no workaround I can use to avoid this issue. Our primary build is Gradle (these are Gradle projects imported) - Eclipse + Groovy-Eclipse is for ease of development. If I can't get this working then I'm going to have to abandon Eclipse (which would be very painful - changing IDEs is no fun).

@eric-milles
Copy link
Member

eric-milles commented Jun 29, 2018

By closing I am not saying that everything is fine. I am presently testing Java 9+ support -- there are definitely known issues.

I understand that you have build issues. If you do not think this is related to the modulepath, please supply some additional details. I'll need to know what your project looks like (.classpath, .project, .settings, build.gradle, etc. -- best to supply a small zip or a github link) I can be reached on Slack if you wish to discuss more quickly/privately.

@magao
Copy link
Author

magao commented Jul 2, 2018

Actually, I think I understand. With the following .project and .classpath, are you saying that JavaSE-10 having modules=true means that Groovy-Eclipse is currently unable to resolve everything it needs to, resulting in this NullPointerException? If we applied my minimal fix, would it just result in compilation failing elsewhere?

If so, do you have any kind of timeframe for when JDK9+ might be supported? Unfortunately, this is a complete showstopper for me ...

Note: I'm using Gradle STS, configured to not export Gradle dependencies ... I've obviously trimmed .classpath below.

.project

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
	<name>util</name>
	<comment></comment>
	<projects/>
	<natures>
		<nature>org.springsource.ide.eclipse.gradle.core.nature</nature>
		<nature>org.eclipse.jdt.core.javanature</nature>
		<nature>org.eclipse.jdt.groovy.core.groovyNature</nature>
	</natures>
	<buildSpec>
		<buildCommand>
			<name>org.eclipse.jdt.core.javabuilder</name>
			<arguments/>
		</buildCommand>
	</buildSpec>
	<linkedResources/>
	<filteredResources/>
</projectDescription>

.classpath

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-10/">
		<attributes>
			<attribute name="module" value="true"/>
		</attributes>
	</classpathentry>
	<classpathentry output="bin/main" kind="src" path="src/main/java">
		<attributes>
			<attribute name="gradle_scope" value="main"/>
			<attribute name="gradle_used_by_scope" value="main,test"/>
		</attributes>
	</classpathentry>
	<classpathentry output="bin/main" kind="src" path="src/main/groovy">
		<attributes>
			<attribute name="gradle_scope" value="main"/>
			<attribute name="gradle_used_by_scope" value="main,test"/>
		</attributes>
	</classpathentry>
	<classpathentry output="bin/main" kind="src" path="src/main/resources">
		<attributes>
			<attribute name="gradle_scope" value="main"/>
			<attribute name="gradle_used_by_scope" value="main,test"/>
		</attributes>
	</classpathentry>
	<classpathentry output="bin/test" kind="src" path="src/test/java">
		<attributes>
			<attribute name="gradle_scope" value="test"/>
			<attribute name="gradle_used_by_scope" value="test"/>
		</attributes>
	</classpathentry>
	<classpathentry output="bin/test" kind="src" path="src/test/groovy">
		<attributes>
			<attribute name="gradle_scope" value="test"/>
			<attribute name="gradle_used_by_scope" value="test"/>
		</attributes>
	</classpathentry>
	<classpathentry output="bin/test" kind="src" path="src/test/resources">
		<attributes>
			<attribute name="gradle_scope" value="test"/>
			<attribute name="gradle_used_by_scope" value="test"/>
		</attributes>
	</classpathentry>
	...
	<classpathentry sourcepath="D:/home/.gradle/caches/modules-2/files-2.1/org.codehaus.groovy/groovy-all/2.4.15/ae189e50a0cc42945c556ab4c7f0f19c6e0faa7c/groovy-all-2.4.15-sources.jar" kind="lib" path="D:/home/.gradle/caches/modules-2/files-2.1/org.codehaus.groovy/groovy-all/2.4.15/423a17aeb2f64bc6f76e8e44265a548bec80fd42/groovy-all-2.4.15.jar">
		<attributes>
			<attribute name="gradle_used_by_scope" value="main,test"/>
		</attributes>
	</classpathentry>

@eric-milles
Copy link
Member

Yes, having a JavaSE-9+ (module=true attribute in classpath) means the rt.jar is replaced by the *.jmod stuff. The GroovyClassLoader/URLClassLoader does not load from these. You could set your JRE container to JavaSE-8 and it would still run on Java 9+. Groovy 2.4 is actually built with Java 6 support.

As for modulepath support, I could restore the ability to run Eclipse with the JDK version you plan to target and so the classes from the JDK would be loaded by Eclipse classloaders. The original issue there is you could be using classes from your Eclipse runtime that would not be available when your project is tested or deployed.

@magao
Copy link
Author

magao commented Jul 2, 2018

Unfortunately I have to use JavaSE-10 as that's the point of the work I'm doing at the moment - getting our code building with the JDK10 compiler.

At least as a short-term option using if using the Eclipse classloaders would give JDK10 support (by running Eclipse under JDK10) then I think that would be preferable to the current situation. Our canonical build is via the command line (and Jenkins) - accidentally using classes that aren't in our gradle dependencies would be quickly caught.

eric-milles added a commit that referenced this issue Jul 2, 2018
for Java 9+ until proper modulepath support can be implemented
@eric-milles
Copy link
Member

@magao
Copy link
Author

magao commented Jul 2, 2018

There are 2 new test failures - is this a problem, or can I test with it?

I updated to the latest e4.7 snapshot and changed my eclipse.ini to use JDK10:

3.0.0.xx-201807021459-e47
eclipse.vm=D:/bin/Java/jdk-10.0.1/bin/server/jvm.dll
java.home=D:\bin\Java\jdk-10.0.1

but still getting the NullPointerException, so either that didn't fix it, or I didn't get the version with the fix due to the test failures.

@eric-milles
Copy link
Member

eric-milles commented Jul 2, 2018

Is it the exact same exception? Are there any errors reported in your Error Log view?

@magao
Copy link
Author

magao commented Jul 3, 2018

While I was doing this a new version came through - 3.0.0.xx-201807022141-e47. Still getting a NullPointerException, but there is one difference - line number change in the stack trace:

org.eclipse.jdt.internal.core.builder.JavaBuilder.build(JavaBuilder.java:175)

(previously was line 180).

Problems occurred when invoking code from plug-in: "org.eclipse.core.resources".
Errors running builder 'Java Builder' on project 'util'.

eclipse.buildId=4.7.3.M20180330-0640
java.version=10.0.1
java.vendor=Oracle Corporation
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=en_AU
Framework arguments: -product org.eclipse.epp.package.java.product
Command-line arguments: -os win32 -ws win32 -arch x86_64 -product org.eclipse.epp.package.java.product

java.lang.NullPointerException
at org.eclipse.jdt.internal.compiler.lookup.Scope.findDirectMemberType(Scope.java:1250)
at org.eclipse.jdt.internal.compiler.lookup.Scope.getTypeOrPackage(Scope.java:3311)
at org.eclipse.jdt.internal.compiler.lookup.Scope.getPackage(Scope.java:2916)
at org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference.getTypeBinding(QualifiedTypeReference.java:104)
at org.eclipse.jdt.internal.compiler.ast.TypeReference.internalResolveType(TypeReference.java:503)
at org.eclipse.jdt.internal.compiler.ast.TypeReference.resolveType(TypeReference.java:607)
at org.eclipse.jdt.internal.compiler.ast.TypeReference.resolveType(TypeReference.java:603)
at org.eclipse.jdt.internal.compiler.ast.TypeReference.resolveType(TypeReference.java:599)
at org.eclipse.jdt.internal.compiler.ast.Annotation.resolveType(Annotation.java:813)
at org.eclipse.jdt.internal.compiler.ast.ASTNode.resolveAnnotations(ASTNode.java:865)
at org.eclipse.jdt.internal.compiler.ast.ASTNode.resolveAnnotations(ASTNode.java:724)
at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.getAnnotationTagBits(SourceTypeBinding.java:1025)
at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.retrieveAnnotationHolder(SourceTypeBinding.java:2355)
at org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding.retrieveAnnotations(ReferenceBinding.java:1724)
at org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding.getAnnotations(ReferenceBinding.java:997)
at org.codehaus.jdt.groovy.internal.compiler.ast.GroovyClassScope$TraitHelper.isTrait(GroovyClassScope.java:525)
at org.codehaus.jdt.groovy.internal.compiler.ast.GroovyClassScope$TraitHelper.access$1(GroovyClassScope.java:518)
at org.codehaus.jdt.groovy.internal.compiler.ast.GroovyClassScope.augmentMethodBindings(GroovyClassScope.java:168)
at org.eclipse.jdt.internal.compiler.lookup.ClassScope.buildMethods(ClassScope.java:387)
at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.initializeForStaticImports(SourceTypeBinding.java:1390)
at org.eclipse.jdt.internal.compiler.lookup.Scope.findField(Scope.java:1424)
at org.eclipse.jdt.internal.compiler.lookup.Scope.findField(Scope.java:1328)
at org.eclipse.jdt.internal.compiler.lookup.Scope.getBinding(Scope.java:2064)
at org.eclipse.jdt.internal.compiler.lookup.BlockScope.getBinding(BlockScope.java:485)
at org.eclipse.jdt.internal.compiler.ast.QualifiedNameReference.resolveType(QualifiedNameReference.java:999)
at org.eclipse.jdt.internal.compiler.ast.MemberValuePair.resolveTypeExpecting(MemberValuePair.java:141)
at org.eclipse.jdt.internal.compiler.ast.Annotation.resolveType(Annotation.java:862)
at org.eclipse.jdt.internal.compiler.ast.ASTNode.resolveAnnotations(ASTNode.java:865)
at org.eclipse.jdt.internal.compiler.ast.ASTNode.resolveAnnotations(ASTNode.java:724)
at org.eclipse.jdt.internal.compiler.lookup.MethodBinding.getAnnotationTagBits(MethodBinding.java:651)
at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.resolveTypesWithSuspendedTempErrorHandlingPolicy(SourceTypeBinding.java:1869)
at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.resolveTypesFor(SourceTypeBinding.java:1849)
at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.methods(SourceTypeBinding.java:1539)
at org.codehaus.jdt.groovy.internal.compiler.ast.GroovyClassScope.buildFieldsAndMethods(GroovyClassScope.java:430)
at org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope.buildFieldsAndMethods(CompilationUnitScope.java:98)
at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.completeTypeBindings(LookupEnvironment.java:514)
at org.eclipse.jdt.internal.compiler.Compiler.internalBeginToCompile(Compiler.java:873)
at org.eclipse.jdt.internal.compiler.Compiler.beginToCompile(Compiler.java:397)
at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:447)
at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:429)
at org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.compile(AbstractImageBuilder.java:396)
at org.eclipse.jdt.internal.core.builder.BatchImageBuilder.compile(BatchImageBuilder.java:191)
at org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.compile(AbstractImageBuilder.java:329)
at org.eclipse.jdt.internal.core.builder.BatchImageBuilder.build(BatchImageBuilder.java:62)
at org.eclipse.jdt.internal.core.builder.JavaBuilder.buildAll(JavaBuilder.java:256)
at org.eclipse.jdt.internal.core.builder.JavaBuilder.build(JavaBuilder.java:175)
at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:735)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:206)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:246)
at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:301)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:304)
at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:360)
at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:383)
at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:142)
at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:232)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:56)

@eric-milles
Copy link
Member

What it's trying to do is resolve the annotations for some method. The annotation attribute is trying to be resolved against the imports. Way down in Scope.getTypeOrPackage(Scope.java:3311) it is checking against the star imports and getting null for the binding (package or type). Last line here is the top of the stack trace:

			// check on demand imports
			if (imports != null) {
				boolean foundInImport = false;
				ReferenceBinding type = null;
				for (int i = 0, length = imports.length; i < length; i++) {
					ImportBinding someImport = imports[i];
					if (someImport.onDemand) {
						Binding resolvedImport = someImport.resolvedImport;
						ReferenceBinding temp = null;
						if (resolvedImport instanceof PackageBinding) {
							temp = findType(name, (PackageBinding) resolvedImport, currentPackage);
						} else if (someImport.isStatic()) {
							// Imports are always resolved in the CU Scope (bug 520874)
							temp = compilationUnitScope().findMemberType(name, (ReferenceBinding) resolvedImport); // static imports are allowed to see inherited member types
							if (temp != null && !temp.isStatic())
								temp = null;
						} else {
							temp = compilationUnitScope().findDirectMemberType(name, (ReferenceBinding) resolvedImport);

I wish I knew what method is being resolved and what annotation is not being resolved properly.

@magao
Copy link
Author

magao commented Jul 3, 2018

I'm wondering if maybe it would be worthwhile doing a temporary variation of my fix - catch the NullPointerException out of findDirectMemberType, log any useful info about it, and then treat it as null (to see if that would at allow compilation to succeed). That would be 2 tests in one.

Hopefully it would either log something related to my source code, or to the groovy-eclipse source - either would be useful info. If it's related to my source it might help be produce a minimal case that you could use to replicate.

@eric-milles
Copy link
Member

Can you search your code for any non-static, on-demand imports like import java.lang.Thread.*? One of these is failing to be found on your project's classpath.

As for logging, the problem is upstream somewhere; a type binding is not found. Have you checked your Error Log view for additional errors?

@eric-milles
Copy link
Member

I am rolling back the recent change that I think is causing a number of NPEs reported in the last few days. Build should be available in a few hours.

@magao
Copy link
Author

magao commented Jul 3, 2018

No other errors at all in the error log. I'm not going to upgrade to any new version yet as I want to test something out to see if it's the cause (see below).

I've changed some package and class names below to be generic (actual code belongs to my employer).

I had:

import static test.utils.CsvConstants.*

but no non-static in groovy code. Changing those to be normal imports (and qualifying the constants in the code) didn't fix the error.

However, additional errors occur afterwards (both with and without the import changes) and they happen to point directly at a related trait - test.utils.CsvUtils (I suspect that might be coincidental though - they are used in the same test code).

The trait is defined like:

TestUtils.groovy:

package test.utils

@CompileStatic
interface CsvConstants {
    final def TYPE_NUMERIC = "${Types.NUMERIC}:NUMERIC"
    final def TYPE_TEXT = "${Types.VARCHAR}:TEXT"
}

trait CsvUtils implements CsvConstants {
    // static methods
}

and then used by test classes like:

class MockObject extends Something implements CsvUtils {
    // code
}

class Test implements CsvUtils {
    // tests
}

in order to mix-in the behaviour to classes that couldn't directly extend it. I might be able to refactor the code to avoid using the trait. This isn't the only trait I have, but I think it's the only one with static methods, so I'll see if that refactoring fixes the issue - I'll let you know.

Exception:

BUG! exception in phase 'canonicalization' in source unit '...\Test.groovy' JDTClassNode.getTypeClass() cannot locate class for test.CsvUtils using transform loader groovy.lang.GroovyClassLoader@1aab131c
	at org.codehaus.jdt.groovy.internal.compiler.ast.JDTClassNode.getTypeClass(JDTClassNode.java:618)
	at org.codehaus.groovy.ast.ClassNode.getTypeClass(ClassNode.java:1488)
	at org.codehaus.groovy.transform.trait.Traits.findHelpers(Traits.java:137)
	at org.codehaus.groovy.transform.trait.TraitComposer.doExtendTraits(TraitComposer.java:111)
	at org.codehaus.groovy.control.CompilationUnit$11.call(CompilationUnit.java:215)
	at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1133)
	at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:626)
	at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:604)
	at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:581)
	at org.codehaus.jdt.groovy.internal.compiler.ast.GroovyCompilationUnitDeclaration.processToPhase(GroovyCompilationUnitDeclaration.java:204)
	at org.codehaus.jdt.groovy.internal.compiler.ast.GroovyCompilationUnitDeclaration.analyseCode(GroovyCompilationUnitDeclaration.java:698)
	at org.eclipse.jdt.internal.compiler.Compiler.resolve(Compiler.java:1067)
	at org.eclipse.jdt.internal.core.CompilationUnitProblemFinder.process(CompilationUnitProblemFinder.java:217)
	at org.codehaus.jdt.groovy.model.GroovyCompilationUnit.buildStructure(GroovyCompilationUnit.java:312)
	at org.eclipse.jdt.internal.core.Openable.generateInfos(Openable.java:259)
	at org.eclipse.jdt.internal.core.SourceRefElement.generateInfos(SourceRefElement.java:107)
	at org.eclipse.jdt.internal.core.JavaElement.openWhenClosed(JavaElement.java:589)
	at org.eclipse.jdt.internal.core.JavaElement.getElementInfo(JavaElement.java:319)
	at org.eclipse.jdt.internal.core.JavaElement.getElementInfo(JavaElement.java:305)
	at org.eclipse.jdt.internal.core.JavaElement.exists(JavaElement.java:223)
	at org.eclipse.jdt.groovy.search.TypeInferencingVisitorWithRequestor.visitImports(TypeInferencingVisitorWithRequestor.java:462)
	at org.eclipse.jdt.groovy.search.TypeInferencingVisitorWithRequestor.visitCompilationUnit(TypeInferencingVisitorWithRequestor.java:239)
	at org.codehaus.jdt.groovy.integration.internal.GroovyLanguageSupport.maybePerformDelegatedSearch(GroovyLanguageSupport.java:264)
	at org.codehaus.jdt.groovy.integration.LanguageSupportFactory.maybePerformDelegatedSearch(LanguageSupportFactory.java:114)
	at org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:1267)
	at org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:1389)
	at org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:1521)
	at org.eclipse.jdt.internal.core.search.JavaSearchParticipant.locateMatches(JavaSearchParticipant.java:122)
	at org.eclipse.jdt.internal.core.search.BasicSearchEngine.findMatches(BasicSearchEngine.java:236)
	at org.eclipse.jdt.internal.core.search.BasicSearchEngine.search(BasicSearchEngine.java:583)
	at org.eclipse.jdt.core.search.SearchEngine.search(SearchEngine.java:608)
	at org.eclipse.jdt.internal.ui.search.JavaSearchQuery.run(JavaSearchQuery.java:175)
	at org.eclipse.search2.internal.ui.InternalSearchUI$InternalSearchJob.run(InternalSearchUI.java:92)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:56)

@magao
Copy link
Author

magao commented Jul 4, 2018

So I've removed all traits from the codebase, replacing with classes where feasible and java interfaces with default methods.

Still getting a NullPointerException in the same location, but quite a different stack trace. So I think we can eliminate traits as being the cause of this.

java.lang.NullPointerException
	at org.eclipse.jdt.internal.compiler.lookup.Scope.findDirectMemberType(Scope.java:1250)
	at org.eclipse.jdt.internal.compiler.lookup.Scope.getTypeOrPackage(Scope.java:3311)
	at org.eclipse.jdt.internal.compiler.lookup.Scope.getType(Scope.java:2993)
	at org.eclipse.jdt.internal.compiler.ast.SingleTypeReference.getTypeBinding(SingleTypeReference.java:51)
	at org.eclipse.jdt.internal.compiler.ast.TypeReference.internalResolveType(TypeReference.java:503)
	at org.eclipse.jdt.internal.compiler.ast.TypeReference.resolveType(TypeReference.java:607)
	at org.eclipse.jdt.internal.compiler.ast.TypeReference.resolveType(TypeReference.java:603)
	at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.resolveTypesWithSuspendedTempErrorHandlingPolicy(SourceTypeBinding.java:1965)
	at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.resolveTypesFor(SourceTypeBinding.java:1849)
	at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.methods(SourceTypeBinding.java:1539)
	at org.codehaus.jdt.groovy.internal.compiler.ast.GroovyClassScope.buildFieldsAndMethods(GroovyClassScope.java:430)
	at org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope.buildFieldsAndMethods(CompilationUnitScope.java:98)
	at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.completeTypeBindings(LookupEnvironment.java:514)
	at org.eclipse.jdt.internal.compiler.Compiler.internalBeginToCompile(Compiler.java:873)
	at org.eclipse.jdt.internal.compiler.Compiler.beginToCompile(Compiler.java:397)
	at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:447)
	at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:429)
	at org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.compile(AbstractImageBuilder.java:396)
	at org.eclipse.jdt.internal.core.builder.BatchImageBuilder.compile(BatchImageBuilder.java:191)
	at org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.compile(AbstractImageBuilder.java:329)
	at org.eclipse.jdt.internal.core.builder.BatchImageBuilder.build(BatchImageBuilder.java:62)
	at org.eclipse.jdt.internal.core.builder.JavaBuilder.buildAll(JavaBuilder.java:256)
	at org.eclipse.jdt.internal.core.builder.JavaBuilder.build(JavaBuilder.java:180)
	at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:735)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:206)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:246)
	at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:301)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:304)
	at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:360)
	at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:383)
	at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:142)
	at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:232)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:56)

@eric-milles eric-milles added the bug label Jul 6, 2018
@eric-milles eric-milles self-assigned this Jul 6, 2018
@eric-milles eric-milles reopened this Jul 12, 2018
@eric-milles eric-milles added this to the v3.0.0 milestone Jul 12, 2018
@eric-milles
Copy link
Member

eric-milles commented Jul 12, 2018

The NPE begins upstream here in GroovyCompilationUnitScope. The call to envirinment.createPackage(javaUtil) is returning a PackageBinding for Java 8 and null for Java 9+.

    protected ImportBinding[] getDefaultImports() {
        if (defaultGroovyImports != null) return defaultGroovyImports;
        List<ImportBinding> importBindings = new ArrayList<>();
        Collections.addAll(importBindings, super.getDefaultImports()); // picks up 'java.lang'

        // augment with the Groovy on-demand imports
        importBindings.add(new ImportBinding(javaIo, true, environment.createPackage(javaIo), null));
        importBindings.add(new ImportBinding(javaNet, true, environment.createPackage(javaNet), null));
        importBindings.add(new ImportBinding(javaUtil, true, environment.createPackage(javaUtil), null));

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