eclipse-jdt / eclipse-jdt/eclipse.jdt.core

ASTParser may fail at reporting some problems

Open
#2,303 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
237
Forks
195
Avg merge
1d 12h
Merged PRs (30d)
47

Description

ASTParser fails at reprorting some problems that CompilationUnitProblemFinder can repo.
Run this test from NullAnnotationsModelTests
```java
public void testBug479389_ASTParser() throws CoreException, IOException {
IJavaProject project = null;
try {
project = createJavaProject("Bug479389", new String[] {"src"}, new String[] {"JCL18_LIB"}, "bin", "1.8");
project.setOption(JavaCore.COMPILER_ANNOTATION_NULL_ANALYSIS, JavaCore.ENABLED);

createFolder("Bug479389/src/nullAnalysis");
String testSource =
"package nullAnalysis;\n" +
"interface MyList {\n" +
" public Stream stream();\n" +
"}\n" +
"interface Stream {\n" +
" T[] toArray(IntFunction supplier);" +
"}\n" +
"interface IntFunction {\n" +
" T apply(int i);\n" +
"}\n" +
"public class X {\n" +
"\n" +
" public String[] method(MyList in) {\n" +
" return in.stream().toArray(String[]::new);\n" +
" }\n" +
"}\n";
String testSourcePath = "Bug479389/src/nullAnalysis/X.java";
createFile(testSourcePath, testSource);

ASTParser parser = ASTParser.newParser(AST.getJLSLatest());
parser.setResolveBindings(true);
parser.setSource(getCompilationUnit(testSourcePath));
parser.setWorkingCopyOwner(this.wcOwner);
CompilationUnit dom = (CompilationUnit)parser.createAST(null);
assertNotEquals(0, dom.getProblems().length);
// expected
// ----------
// . ERROR in /Bug479389/src/nullAnalysis/X.java (at line 13)
// return in.stream().toArray(String[]::new);
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// Annotation type 'org.eclipse.jdt.annotation.NonNull' cannot be found on the build path, which is implicitly needed for null analysis
// ---------
} finally {
deleteProject(project);
}
}
```
and see it fail to report the expected error.
I tried to investigate a bit more, and got convinced that the issue is that the CompilationUnitResolver seems to not set the right ErrorHandlingPolicy for its various steps (or fails at overriding one method which changes that is supposed to change it).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.