eclipse-jdt / eclipse-jdt/eclipse.jdt.core
ASTParser sometimes failing at resolving package with modules
- Dominant language
- Java
- Stars
- 237
- Forks
- 195
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 47
Description
Add this to ModuleBuilderTests
```java
public void testAutoModule3_ASTParser() throws Exception {
IJavaProject javaProject = null, auto = null;
try {
auto = createJava9Project("auto", new String[] {"src"});
createFolder("auto/src/p/a");
createFile("auto/src/p/a/X.java",
"package p.a;\n" +
"public class X {}\n;");
createFolder("auto/META-INF");
createFile("auto/META-INF/MANIFEST.MF",
"Manifest-Version: 1.0\n" +
"Automatic-Module-Name: org.eclipse.lib.x\n");
javaProject = createJava9Project("mod.one", new String[] {"src"});
IClasspathAttribute[] attributes = { JavaCore.newClasspathAttribute(IClasspathAttribute.MODULE, "true") };
addClasspathEntry(javaProject, JavaCore.newProjectEntry(auto.getPath(), null, false, attributes, false));
String srcMod =
"module mod.one { \n" +
" requires org.eclipse.lib.x;\n" + // from manifest attribute
"}";
createFile("/mod.one/src/module-info.java",
srcMod);
createFolder("mod.one/src/q");
String srcX =
"package q;\n" +
"public class X {\n" +
" p.a.X f;\n" +
"}";
createFile("/mod.one/src/q/X.java", srcX);
auto.getProject().build(IncrementalProjectBuilder.FULL_BUILD, null);
ASTParser parser = ASTParser.newParser(AST.getJLSLatest());
parser.setResolveBindings(true);
parser.setProject(javaProject);
parser.setSource(getWorkingCopy("/mod.one/src/q/X.java", srcX, true));
CompilationUnit unit = (CompilationUnit) parser.createAST(null);
assertArrayEquals(new IProblem[0], unit.getProblems());
} finally {
if (javaProject != null)
deleteProject(javaProject);
if (auto != null)
deleteProject(auto);
}
}
```
and see it wrongly fail with
```
array lengths differed, expected.length=0 actual.length=1; arrays first differed at element [0]; expected: but was:
at org.junit.internal.ComparisonCriteria.arrayEquals(ComparisonCriteria.java:89)
at org.junit.internal.ComparisonCriteria.arrayEquals(ComparisonCriteria.java:28)
at org.junit.Assert.internalArrayEquals(Assert.java:534)
at org.junit.Assert.assertArrayEquals(Assert.java:285)
at org.junit.Assert.assertArrayEquals(Assert.java:300)
at org.eclipse.jdt.core.tests.model.ModuleBuilderTests.testAutoModule3_ASTParser(ModuleBuilderTests.java:5331)
```
When working on this with #2300, the proposed quickfix was causing a StackOverflowError that can be reproduced when applying the patch and running this from ResolveTests9
```java
public void testModuleInfo_ASTParser() throws CoreException {
IFile providesFile = createFile("/Resolve/src/provides.java", "public class provides {}");
IFile modInfo = null;
try {
getWorkingCopy(
"/Resolve/src/test/ITest.java",
"public interface ITest {}\n");
getWorkingCopy(
"/Resolve/src/test/TestClass.java",
"public class TestClass implements ITest {}\n");
this.wc = getWorkingCopy(
"/Resolve/src/module-info.java",
"module com.test {\n" +
" provides p1.Y with ResolveInterface;\n" +
"}\n");
ASTParser parser = ASTParser.newParser(AST.getJLSLatest());
parser.setResolveBindings(true);
parser.setProject(this.currentProject);
parser.setSource(this.wc);
CompilationUnit unit = (CompilationUnit) parser.createAST(null);
assertArrayEquals(new IProblem[0], unit.getProblems());
} finally {
deleteResource(providesFile);
if (modInfo != null)
deleteResource(modInfo);
}
}
```
Contributor guide
Assessment
This issue has not been assessed yet.