Skip to content

Commit

Permalink
Fixing regressions:
Browse files Browse the repository at this point in the history
+ Java50Tests pointed to incomplete impl. at compliance below 1.8
  => restrict new policy to 1.8+
+ DependencyTests.testMissingClassFile()
  + bump test to 1.8 and let it include positive & negative cases
+ MultiProjectTests.test461074_error() split to 1.5 and 1.8 variants:
  + no change at 1.5
  + no longer an error at 1.8+
  • Loading branch information
stephan-herrmann committed Jun 9, 2024
1 parent a8edd5e commit bd1cc36
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1952,7 +1952,7 @@ MethodBinding resolveTypesFor(MethodBinding method) {
if ((method.modifiers & ExtraCompilerModifiers.AccUnresolved) == 0)
return method;
boolean tolerateSave = this.environment.mayTolerateMissingType;
this.environment.mayTolerateMissingType = true;
this.environment.mayTolerateMissingType = this.environment.globalOptions.complianceLevel >= ClassFileConstants.JDK1_8; // tolerance only implemented for 1.8+
try {

if (!method.isConstructor()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@

@SuppressWarnings({"rawtypes", "unchecked"})
public class DependencyTests extends BuilderTests {
static {
// TESTS_NAMES = new String[] {"testMissingClassFile"};
}
public DependencyTests(String name) {
super(name);
}
Expand Down Expand Up @@ -857,7 +860,7 @@ public void testMethodVisibility() throws JavaModelException {
}

public void testMissingClassFile() throws JavaModelException {
IPath project1Path = env.addProject("Project1"); //$NON-NLS-1$
IPath project1Path = env.addProject("Project1", "1.8"); // tolerance of missing types not fully implemented below 1.8
env.addExternalJars(project1Path, Util.getJavaClassLibs());

// remove old package fragment root so that names don't collide
Expand All @@ -871,7 +874,7 @@ public void testMissingClassFile() throws JavaModelException {
"public class MissingClass {}" //$NON-NLS-1$
);

IPath project2Path = env.addProject("Project2"); //$NON-NLS-1$
IPath project2Path = env.addProject("Project2", "1.8"); // tolerance of missing types not fully implemented below 1.8
env.addExternalJars(project2Path, Util.getJavaClassLibs());
env.addRequiredProject(project2Path, project1Path);

Expand All @@ -890,7 +893,7 @@ public void testMissingClassFile() throws JavaModelException {
"}\n" //$NON-NLS-1$
);

IPath project3Path = env.addProject("Project3"); //$NON-NLS-1$
IPath project3Path = env.addProject("Project3", "1.8"); // tolerance of missing types not fully implemented below 1.8
env.addExternalJars(project3Path, Util.getJavaClassLibs());
env.addRequiredProject(project3Path, project2Path);
// missing required Project1 so MissingClass cannot be found
Expand All @@ -906,19 +909,20 @@ public void testMissingClassFile() throws JavaModelException {
"import p2.A;\n" +
"public class B {\n"+ //$NON-NLS-1$
" public static void main(String[] args) {\n" + //$NON-NLS-1$
" new A().foo(new String());\n" + //$NON-NLS-1$
" new A().foo(new Object());\n" + // potentially ambiguous
" new A().foo(new String());\n" + // exact match to fully resolved method
" }\n" + //$NON-NLS-1$
"}\n" //$NON-NLS-1$
);

fullBuild();
expectingOnlyProblemsFor(new IPath[] {project3Path, bPath});
expectingSpecificProblemFor(project3Path, new Problem("Project3", "The project was not built since its build path is incomplete. Cannot find the class file for p1.MissingClass. Fix the build path then try building this project", project3Path, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
expectingSpecificProblemFor(bPath, new Problem("B", "The type p1.MissingClass cannot be resolved. It is indirectly referenced from required type p2.A", bPath, 86, 111, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
expectingOnlyProblemsFor(new IPath[] {bPath});
expectingSpecificProblemFor(bPath, new Problem("B", "The method foo(MissingClass) from the type A refers to the missing type MissingClass", bPath, 94, 97, CategorizedProblem.CAT_MEMBER, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$

env.addClass(root2, "p2", "A", //$NON-NLS-1$ //$NON-NLS-2$
"package p2;\n"+ //$NON-NLS-1$
"public class A {\n"+ //$NON-NLS-1$
" public void foo(Object data) {}\n"+ //$NON-NLS-1$
" public void foo(String data) {}\n"+ //$NON-NLS-1$
"}\n" //$NON-NLS-1$
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
@SuppressWarnings({"rawtypes", "unchecked"})
public class MultiProjectTests extends BuilderTests {

static {
TESTS_NAMES = new String[] { "test461074_error_1_8" };
}

public MultiProjectTests(String name) {
super(name);
}
Expand Down Expand Up @@ -2221,4 +2225,76 @@ public void test461074_error() throws JavaModelException {
env.removeProject(p2);
env.removeProject(p3);
}
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=461074, "indirectly referenced from required .class files" error for unreachable reference of type in overriding method declaration in a library on classpath
public void test461074_error_1_8() throws JavaModelException {
// as of https://github.com/eclipse-jdt/eclipse.jdt.core/pull/2543 and at 1.8+ we tolerate the missing type
//----------------------------
// Project1
//----------------------------
IPath p1 = env.addProject("SampleMissing", "1.8"); //$NON-NLS-1$
env.addExternalJars(p1, Util.getJavaClassLibs());
// remove old package fragment root so that names don't collide
env.removePackageFragmentRoot(p1, ""); //$NON-NLS-1$
IPath root1 = env.addPackageFragmentRoot(p1, "src"); //$NON-NLS-1$
env.setOutputFolder(p1, "bin"); //$NON-NLS-1$

env.addClass(root1, "pack.missing", "MissingType", //$NON-NLS-1$ //$NON-NLS-2$
"package pack.missing;\n" +
"public class MissingType {\n" +
"}\n"
);

//----------------------------
// Project2
//----------------------------
IPath p2 = env.addProject("SampleLib", "1.8"); //$NON-NLS-1$
env.addExternalJars(p2, Util.getJavaClassLibs());
// remove old package fragment root so that names don't collide
env.removePackageFragmentRoot(p2, ""); //$NON-NLS-1$
IPath root2 = env.addPackageFragmentRoot(p2, "src"); //$NON-NLS-1$
env.setOutputFolder(p2, "bin"); //$NON-NLS-1$

env.addClass(root2, "pack.lib", "TopClass", //$NON-NLS-1$ //$NON-NLS-2$
"package pack.lib;\n" +
"public abstract class TopClass {\n" +
" abstract Object get();\n" +
"}\n"
);
env.addClass(root2, "pack.lib", "SuperClass", //$NON-NLS-1$ //$NON-NLS-2$
"package pack.lib;\n" +
"import pack.missing.MissingType;\n" +
"public class SuperClass extends TopClass {\n" +
" @Override\n" +
" MissingType get() { return null; }\n" +
"}\n"
);

//----------------------------
// Project3
//----------------------------
IPath p3 = env.addProject("SampleTest", "1.8"); //$NON-NLS-1$
env.addExternalJars(p3, Util.getJavaClassLibs());
// remove old package fragment root so that names don't collide
env.removePackageFragmentRoot(p3, ""); //$NON-NLS-1$
IPath root3 = env.addPackageFragmentRoot(p3, "src"); //$NON-NLS-1$
env.setOutputFolder(p3, "bin"); //$NON-NLS-1$

env.addClass(root3, "pack.test", "Test", //$NON-NLS-1$ //$NON-NLS-2$
"package pack.test;\n" +
"import pack.lib.SuperClass;\n" +
"public class Test extends SuperClass {/*empty*/}\n"
);

// for Project1
env.addRequiredProject(p2, p1);
env.addRequiredProject(p3, p2);
env.waitForManualRefresh();
fullBuild();
env.waitForAutoBuild();
expectingNoProblemsFor(p3);
env.setBuildOrder(null);
env.removeProject(p1);
env.removeProject(p2);
env.removeProject(p3);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ public void test004() {
}
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation
public void test005() {
if (this.complianceLevel < ClassFileConstants.JDK1_8) return; // ignore different outcome below 1.8 since PR 2543
this.runConformTest(
new String[] {
"p/OtherFoo.java", //-----------------------------------------------------------------------
Expand Down Expand Up @@ -510,6 +511,7 @@ public void test005() {
}
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation
public void test006() {
if (this.complianceLevel < ClassFileConstants.JDK1_8) return; // ignore different outcome below 1.8 since PR 2543
this.runConformTest(
new String[] {
"p/OtherFoo.java", //-----------------------------------------------------------------------
Expand Down Expand Up @@ -572,6 +574,7 @@ public void test006() {
}
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation
public void test007() {
if (this.complianceLevel < ClassFileConstants.JDK1_8) return; // ignore different outcome below 1.8 since PR 2543
this.runConformTest(
new String[] {
"p/OtherFoo.java", //-----------------------------------------------------------------------
Expand Down Expand Up @@ -8814,6 +8817,7 @@ public void testBug576735() {
runner.runNegativeTest();
}
public void testMissingClassNeededForOverloadResolution() {
if (this.complianceLevel < ClassFileConstants.JDK1_8) return; // ignore different outcome below 1.8 since PR 2543
Runner runner = new Runner();
runner.testFiles = new String[] {
"p1/A.java",
Expand Down Expand Up @@ -8876,7 +8880,7 @@ The method m(A) from the type B refers to the missing type A
runner.runNegativeTest();
}
public void testMissingClassNeededForOverloadResolution_varargs1() {
if (this.complianceLevel < ClassFileConstants.JDK1_5) return; // uses varargs
if (this.complianceLevel < ClassFileConstants.JDK1_8) return; // ignore different outcome below 1.8 since PR 2543
Runner runner = new Runner();
runner.customOptions = getCompilerOptions();
runner.testFiles = new String[] {
Expand Down Expand Up @@ -8948,7 +8952,7 @@ The method n(Object, A...) from the type B refers to the missing type A
runner.runNegativeTest();
}
public void testMissingClassNeededForOverloadResolution_varargs2() {
if (this.complianceLevel < ClassFileConstants.JDK1_5) return; // uses varargs
if (this.complianceLevel < ClassFileConstants.JDK1_8) return; // ignore different outcome below 1.8 since PR 2543
Runner runner = new Runner();
runner.testFiles = new String[] {
"p1/A.java",
Expand Down

0 comments on commit bd1cc36

Please sign in to comment.