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

The type javax.annotation.Nullable cannot be resolved. It is indirectly referenced from required .class files #925

Closed
msteinbeck opened this issue Nov 3, 2016 · 17 comments

Comments

@msteinbeck
Copy link
Contributor

I get the following error when running Spoon in noclasspath mode on Guava (commit: 221de73a17f4c5f2b913c5b0c640d54aa1000f94):

org.eclipse.jdt.internal.compiler.problem.AbortCompilation: Pb(324) The type javax.annotation.Nullable cannot be resolved. It is indirectly referenced from required .class files
	at org.eclipse.jdt.internal.compiler.problem.ProblemHandler.handle(ProblemHandler.java:159)
	at org.eclipse.jdt.internal.compiler.problem.ProblemHandler.handle(ProblemHandler.java:226)
	at org.eclipse.jdt.internal.compiler.problem.ProblemReporter.handle(ProblemReporter.java:2391)
	at org.eclipse.jdt.internal.compiler.problem.ProblemReporter.isClassPathCorrect(ProblemReporter.java:4727)
	at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.getTypeFromCompoundName(LookupEnvironment.java:1324)
	at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.getTypeFromConstantPoolName(LookupEnvironment.java:1354)
	at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.getTypeFromConstantPoolName(LookupEnvironment.java:1362)
	at org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.createAnnotation(BinaryTypeBinding.java:168)
	at org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.createAnnotations(BinaryTypeBinding.java:176)
	at org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.createMethod(BinaryTypeBinding.java:796)
	at org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.createMethods(BinaryTypeBinding.java:912)
	at org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.cachePartsFrom(BinaryTypeBinding.java:524)
	at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.createBinaryTypeFrom(LookupEnvironment.java:722)
	at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.createBinaryTypeFrom(LookupEnvironment.java:705)
	at org.eclipse.jdt.internal.compiler.Compiler.accept(Compiler.java:301)
	at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.askForType(LookupEnvironment.java:180)
	at org.eclipse.jdt.internal.compiler.lookup.PackageBinding.getTypeOrPackage(PackageBinding.java:214)
	at org.eclipse.jdt.internal.compiler.lookup.Scope.getTypeOrPackage(Scope.java:3228)
	at org.eclipse.jdt.internal.compiler.lookup.Scope.getType(Scope.java:2940)
	at org.eclipse.jdt.internal.compiler.ast.SingleTypeReference.getTypeBinding(SingleTypeReference.java:51)
	at org.eclipse.jdt.internal.compiler.ast.TypeReference.internalResolveType(TypeReference.java:495)
	at org.eclipse.jdt.internal.compiler.ast.TypeReference.resolveType(TypeReference.java:586)
	at org.eclipse.jdt.internal.compiler.ast.TypeReference.resolveType(TypeReference.java:582)
	at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.resolveTypeFor(SourceTypeBinding.java:1759)
	at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.fields(SourceTypeBinding.java:934)
	at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.internalFaultInTypeForFieldsAndMethods(SourceTypeBinding.java:903)
	at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.internalFaultInTypeForFieldsAndMethods(SourceTypeBinding.java:907)
	at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.faultInTypesForFieldsAndMethods(SourceTypeBinding.java:899)
	at org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope.faultInTypes(CompilationUnitScope.java:448)
	at spoon.support.compiler.jdt.TreeBuilderCompiler.buildUnits(TreeBuilderCompiler.java:58)
	at spoon.support.compiler.jdt.JDTBatchCompiler.getUnits(JDTBatchCompiler.java:156)
	at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.buildSources(JDTBasedSpoonCompiler.java:444)
	at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.build(JDTBasedSpoonCompiler.java:130)
	at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.build(JDTBasedSpoonCompiler.java:113)
	at spoon.Launcher.buildModel(Launcher.java:711)

Shouldn't noclasspath mode ignore missing dependencies?

@tdurieux
Copy link
Collaborator

tdurieux commented Nov 3, 2016

Which version of spoon do toi use?

@msteinbeck
Copy link
Contributor Author

5.4.0 from Maven Central.

@tdurieux
Copy link
Collaborator

tdurieux commented Nov 3, 2016

strange. #820 fixes the issue for me...

It does not seam possible to disable the JDT exception. Sorry

@tdurieux
Copy link
Collaborator

tdurieux commented Nov 3, 2016

Can you try to replace the line: https://github.com/INRIA/spoon/blob/master/src/main/java/spoon/support/compiler/jdt/JDTBatchCompiler.java#L122
by

CommentRecorderParser parser =
                    new CommentRecorderParser(
                            new ProblemReporter(
                                    DefaultErrorHandlingPolicies.ignoreAllProblems(), // changed arg
                                    compilerOptions,
                                    new DefaultProblemFactory(Locale.getDefault())),
                            false);

@msteinbeck
Copy link
Contributor Author

It doesn't make any difference; I still get the same error.

@tdurieux
Copy link
Collaborator

tdurieux commented Nov 3, 2016

One hardcore "solution" is to overwrite the method handle of ProblemReporter to bypass the JDT exception.
@monperrus What do you think?

@monperrus
Copy link
Collaborator

is to overwrite the method handle of ProblemReporter to bypass the JDT exception.

in noclasspath, it makes perfectly sense.

@msteinbeck
Copy link
Contributor Author

@monperrus, @tdurieux: Since I have no experience with JDT related exception, I would be delighted I one of you could fix this issue.

@tdurieux
Copy link
Collaborator

tdurieux commented Nov 7, 2016

Hello,
can you try to change the line https://github.com/INRIA/spoon/blob/master/src/main/java/spoon/support/compiler/jdt/JDTBatchCompiler.java#L109
from

environment, getHandlingPolicy(), compilerOptions,

to

environment, DefaultErrorHandlingPolicies.ignoreAllProblems(), compilerOptions,

@msteinbeck
Copy link
Contributor Author

Applying your patch yields to another error (I'm using the most recent version of Spoon 801d1cd):

java.lang.NullPointerException
    at org.eclipse.jdt.internal.compiler.ast.AllocationExpression.analyseCode(AllocationExpression.java:94)
    at org.eclipse.jdt.internal.compiler.ast.LocalDeclaration.analyseCode(LocalDeclaration.java:89)
    at org.eclipse.jdt.internal.compiler.ast.MethodDeclaration.analyseCode(MethodDeclaration.java:125)
    at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.internalAnalyseCode(TypeDeclaration.java:739)
    at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.analyseCode(TypeDeclaration.java:263)
    at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.analyseCode(CompilationUnitDeclaration.java:118)
    at spoon.support.compiler.jdt.TreeBuilderCompiler.buildUnits(TreeBuilderCompiler.java:70)
    at spoon.support.compiler.jdt.JDTBatchCompiler.getUnits(JDTBatchCompiler.java:120)
    at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.buildSources(JDTBasedSpoonCompiler.java:372)
    at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.build(JDTBasedSpoonCompiler.java:115)
    at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.build(JDTBasedSpoonCompiler.java:98)
    at spoon.Launcher.buildModel(Launcher.java:699)

In the following you can see the output of git diff:

diff --git a/src/main/java/spoon/support/compiler/jdt/JDTBatchCompiler.java b/src/main/java/spoon/support/compiler/jdt/JDTBatchCompiler.java
index 90c163e..4954dcb 100644
--- a/src/main/java/spoon/support/compiler/jdt/JDTBatchCompiler.java
+++ b/src/main/java/spoon/support/compiler/jdt/JDTBatchCompiler.java
@@ -109,7 +109,7 @@ public class JDTBatchCompiler extends org.eclipse.jdt.internal.compiler.batch.Ma
                CompilerOptions compilerOptions = new CompilerOptions(this.options);
                compilerOptions.parseLiteralExpressionsAsConstants = false;
                TreeBuilderCompiler treeBuilderCompiler = new TreeBuilderCompiler(
-                               environment, getHandlingPolicy(), compilerOptions,
+                               environment, DefaultErrorHandlingPolicies.ignoreAllProblems(), compilerOptions,
                                this.jdtCompiler.requestor, getProblemFactory(), this.out,
                                null);
                if (jdtCompiler.getEnvironment().getNoClasspath()) {

@tdurieux
Copy link
Collaborator

tdurieux commented Nov 9, 2016

Thank you. I will investigate.

This time I will reproduce the bug ...

@msteinbeck
Copy link
Contributor Author

Any progress here?

@tdurieux
Copy link
Collaborator

Sorry I did not have the time to work on it.

@surli
Copy link
Collaborator

surli commented Dec 14, 2016

@ReTuXx I just try to reproduce your bug with a very very simple testcase:

@Test
public void testGuava() throws Exception {
	final Launcher launcher = new Launcher();
	launcher.getEnvironment().setNoClasspath(true);
	launcher.addInputResource("/Users/urli/Github/guava/src");
	launcher.setSourceOutputDirectory("/tmp/guava");
	launcher.run();

	assertTrue(launcher.getModel().getRootPackage() != null);
}

Just tried with the version of Guava you mentioned, with both last version of spoon and the version from commit you reference: all is passing here...

Could you give me more info to reproduce the bug here?

@surli
Copy link
Collaborator

surli commented Dec 20, 2016

@ReTuXx any news here?

@msteinbeck
Copy link
Contributor Author

Working on it. You'll get an update tomorrow.

@msteinbeck
Copy link
Contributor Author

It looks like the error occurs only when using our incremental Spoon model update approach because the error doesn't show up when spooning the revision by its own. I'll close this issue because it is not Spoon related.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants