### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: compiler/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java,v retrieving revision 1.179 diff -u -r1.179 ClassScope.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java 19 Jul 2010 16:42:35 -0000 1.179 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java 20 Jul 2010 06:40:06 -0000 @@ -11,6 +11,7 @@ package org.eclipse.jdt.internal.compiler.lookup; import java.util.HashMap; +import java.util.Iterator; import java.util.Map; import org.eclipse.jdt.core.compiler.CharOperation; @@ -1028,8 +1029,10 @@ SourceTypeBinding sourceType = this.referenceContext.binding; if ((sourceType.tagBits & TagBits.BeginHierarchyCheck) == 0) { sourceType.tagBits |= TagBits.BeginHierarchyCheck; + environment().typesBeingConnected.add(sourceType); boolean noProblems = connectSuperclass(); noProblems &= connectSuperInterfaces(); + environment().typesBeingConnected.remove(sourceType); sourceType.tagBits |= TagBits.EndHierarchyCheck; noProblems &= connectTypeVariables(this.referenceContext.typeParameters, false); sourceType.tagBits |= TagBits.TypeVariablesAreConnected; @@ -1065,8 +1068,10 @@ return; sourceType.tagBits |= TagBits.BeginHierarchyCheck; + environment().typesBeingConnected.add(sourceType); boolean noProblems = connectSuperclass(); noProblems &= connectSuperInterfaces(); + environment().typesBeingConnected.remove(sourceType); sourceType.tagBits |= TagBits.EndHierarchyCheck; noProblems &= connectTypeVariables(this.referenceContext.typeParameters, false); sourceType.tagBits |= TagBits.TypeVariablesAreConnected; @@ -1168,12 +1173,26 @@ org.eclipse.jdt.internal.compiler.ast.TypeReference ref = ((SourceTypeBinding) superType).scope.superTypeReference; // https://bugs.eclipse.org/bugs/show_bug.cgi?id=133071 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=121734 - if (ref != null && (ref.resolvedType == null || ((ReferenceBinding) ref.resolvedType).isHierarchyBeingActivelyConnected())) { + if (ref != null && ref.resolvedType != null && ((ReferenceBinding) ref.resolvedType).isHierarchyBeingActivelyConnected()) { problemReporter().hierarchyCircularity(sourceType, superType, reference); sourceType.tagBits |= TagBits.HierarchyHasProblems; superType.tagBits |= TagBits.HierarchyHasProblems; return true; } + if (ref != null && ref.resolvedType == null) { + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=319885 Don't cry foul prematurely. + // Check the edges traversed to see if there really is a cycle. + char [] referredName = ref.getLastToken(); + for (Iterator iter = environment().typesBeingConnected.iterator(); iter.hasNext();) { + SourceTypeBinding type = (SourceTypeBinding) iter.next(); + if (CharOperation.equals(referredName, type.sourceName())) { + problemReporter().hierarchyCircularity(sourceType, superType, reference); + sourceType.tagBits |= TagBits.HierarchyHasProblems; + superType.tagBits |= TagBits.HierarchyHasProblems; + return true; + } + } + } } if ((superType.tagBits & TagBits.BeginHierarchyCheck) == 0) // ensure if this is a source superclass that it has already been checked Index: compiler/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java,v retrieving revision 1.105 diff -u -r1.105 LookupEnvironment.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java 9 Feb 2010 05:14:15 -0000 1.105 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java 20 Jul 2010 06:40:09 -0000 @@ -12,7 +12,9 @@ import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.Map; +import java.util.Set; import org.eclipse.jdt.core.compiler.CharOperation; import org.eclipse.jdt.internal.compiler.ClassFilePool; @@ -65,6 +67,7 @@ public MethodBinding arrayClone; private ArrayList missingTypes; + Set typesBeingConnected; public boolean isProcessingAnnotations = false; final static int BUILD_FIELDS_AND_METHODS = 4; @@ -92,6 +95,7 @@ this.missingTypes = null; this.accessRestrictions = new HashMap(3); this.classFilePool = ClassFilePool.newInstance(); + this.typesBeingConnected = new HashSet(); } /** @@ -1348,6 +1352,7 @@ this.uniqueParameterizedGenericMethodBindings = new SimpleLookupTable(3); this.uniqueGetClassMethodBinding = null; this.missingTypes = null; + this.typesBeingConnected = new HashSet(); for (int i = this.units.length; --i >= 0;) this.units[i] = null; #P org.eclipse.jdt.core.tests.compiler Index: src/org/eclipse/jdt/core/tests/compiler/regression/InnerClass15Test.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InnerClass15Test.java,v retrieving revision 1.1 diff -u -r1.1 InnerClass15Test.java --- src/org/eclipse/jdt/core/tests/compiler/regression/InnerClass15Test.java 21 Jun 2010 09:48:09 -0000 1.1 +++ src/org/eclipse/jdt/core/tests/compiler/regression/InnerClass15Test.java 20 Jul 2010 06:40:15 -0000 @@ -139,6 +139,290 @@ "The type X is never used locally\n" + "----------\n"); } +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=319885 +public void test005() { + this.runNegativeTest(new String[] { + "p1/GreenBox.java", + "package p1;\n" + + "import static p1.BrownBox.*;\n" + + "public interface GreenBox {\n" + + " public static class Cat extends Object {}\n" + + "}\n", + "p1/BrownBox.java", + "package p1;\n" + + "import static p1.GreenBox.*;\n" + + "public interface BrownBox {\n" + + " public static class BlackCat extends Cat {}\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in p1\\GreenBox.java (at line 2)\n" + + " import static p1.BrownBox.*;\n" + + " ^^^^^^^^^^^\n" + + "The import p1.BrownBox is never used\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=319885 +public void test006() { + this.runNegativeTest(new String[] { + "p1/BrownBox.java", + "package p1;\n" + + "import static p1.GreenBox.*;\n" + + "public interface BrownBox {\n" + + " public static class BlackCat extends Cat {}\n" + + "}\n", + "p1/GreenBox.java", + "package p1;\n" + + "import static p1.BrownBox.*;\n" + + "public interface GreenBox {\n" + + " public static class Cat extends Object {}\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in p1\\GreenBox.java (at line 2)\n" + + " import static p1.BrownBox.*;\n" + + " ^^^^^^^^^^^\n" + + "The import p1.BrownBox is never used\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=319885 +public void test007() { + this.runNegativeTest(new String[] { + "p1/BrownBox.java", + "package p1;\n" + + "import static p1.GreenBox.*;\n" + + "public interface BrownBox {\n" + + " public static class BlackCat extends Cat {}\n" + + "}\n", + "p1/GreenBox.java", + "package p1;\n" + + "import static p1.BrownBox.*;\n" + + "public interface GreenBox {\n" + + " public static class Cat extends java.lang.Object {}\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in p1\\GreenBox.java (at line 2)\n" + + " import static p1.BrownBox.*;\n" + + " ^^^^^^^^^^^\n" + + "The import p1.BrownBox is never used\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=319885 +public void test008() { + this.runNegativeTest(new String[] { + "p1/BrownBox.java", + "package p1;\n" + + "import static p1.GreenBox.*;\n" + + "public interface BrownBox {\n" + + " public static class BlackCat extends Cat {}\n" + + "}\n", + "p1/GreenBox.java", + "package p1;\n" + + "import static p1.BrownBox.*;\n" + + "public interface GreenBox {\n" + + " public static class Cat extends BlackCat {}\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in p1\\BrownBox.java (at line 4)\n" + + " public static class BlackCat extends Cat {}\n" + + " ^^^^^^^^\n" + + "The hierarchy of the type BlackCat is inconsistent\n" + + "----------\n" + + "----------\n" + + "1. ERROR in p1\\GreenBox.java (at line 4)\n" + + " public static class Cat extends BlackCat {}\n" + + " ^^^^^^^^\n" + + "Cycle detected: a cycle exists in the type hierarchy between GreenBox.Cat and BrownBox.BlackCat\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=319885 +public void test009() { + this.runNegativeTest(new String[] { + "p1/GreenBox.java", + "package p1;\n" + + "import static p1.BrownBox.*;\n" + + "public interface GreenBox {\n" + + " public static class Cat extends BlackCat {}\n" + + "}\n", + "p1/BrownBox.java", + "package p1;\n" + + "import static p1.GreenBox.*;\n" + + "public interface BrownBox {\n" + + " public static class BlackCat extends Cat {}\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in p1\\GreenBox.java (at line 4)\n" + + " public static class Cat extends BlackCat {}\n" + + " ^^^\n" + + "The hierarchy of the type Cat is inconsistent\n" + + "----------\n" + + "----------\n" + + "1. ERROR in p1\\BrownBox.java (at line 4)\n" + + " public static class BlackCat extends Cat {}\n" + + " ^^^\n" + + "Cycle detected: a cycle exists in the type hierarchy between BrownBox.BlackCat and GreenBox.Cat\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=319885 +public void test0010() { + this.runNegativeTest(new String[] { + "p1/GreenBox.java", + "package p1;\n" + + "import static p1.BrownBox.*;\n" + + "interface SuperInterface {\n" + + " public static class Cat extends BlackCat {}\n" + + "}\n" + + "public interface GreenBox {\n" + + "}\n", + "p1/BrownBox.java", + "package p1;\n" + + "import static p1.GreenBox.*;\n" + + "public interface BrownBox {\n" + + " public static class BlackCat extends Cat {}\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in p1\\GreenBox.java (at line 4)\n" + + " public static class Cat extends BlackCat {}\n" + + " ^^^\n" + + "The hierarchy of the type Cat is inconsistent\n" + + "----------\n" + + "----------\n" + + "1. ERROR in p1\\BrownBox.java (at line 4)\n" + + " public static class BlackCat extends Cat {}\n" + + " ^^^\n" + + "Cat cannot be resolved to a type\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=319885 +public void test0011() { + this.runNegativeTest(new String[] { + "p1/GreenBox.java", + "package p1;\n" + + "import static p1.BrownBox.*;\n" + + "interface SuperInterface {\n" + + " public static class Cat extends BlackCat {}\n" + + "}\n" + + "public interface GreenBox extends SuperInterface {\n" + + "}\n", + "p1/BrownBox.java", + "package p1;\n" + + "import static p1.GreenBox.*;\n" + + "public interface BrownBox {\n" + + " public static class BlackCat extends Cat {}\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in p1\\GreenBox.java (at line 4)\n" + + " public static class Cat extends BlackCat {}\n" + + " ^^^\n" + + "The hierarchy of the type Cat is inconsistent\n" + + "----------\n" + + "----------\n" + + "1. ERROR in p1\\BrownBox.java (at line 4)\n" + + " public static class BlackCat extends Cat {}\n" + + " ^^^\n" + + "Cycle detected: a cycle exists in the type hierarchy between BrownBox.BlackCat and SuperInterface.Cat\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=319885 +public void test0012() { + this.runNegativeTest(new String[] { + "p1/GreenBox.java", + "package p1;\n" + + "import static p1.BrownBox.*;\n" + + "interface SuperInterface {\n" + + " public static class Cat extends BlackCat {}\n" + + "}\n" + + "public interface GreenBox extends SuperInterface {\n" + + "}\n", + "p1/BrownBox.java", + "package p1;\n" + + "import static p1.GreenBox.*;\n" + + "public interface BrownBox {\n" + + " public static class BlackCat extends GreenBox.Cat {}\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in p1\\GreenBox.java (at line 4)\n" + + " public static class Cat extends BlackCat {}\n" + + " ^^^\n" + + "The hierarchy of the type Cat is inconsistent\n" + + "----------\n" + + "----------\n" + + "1. ERROR in p1\\BrownBox.java (at line 4)\n" + + " public static class BlackCat extends GreenBox.Cat {}\n" + + " ^^^^^^^^^^^^\n" + + "Cycle detected: a cycle exists in the type hierarchy between BrownBox.BlackCat and SuperInterface.Cat\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=319885 +public void test0013() { + this.runNegativeTest(new String[] { + "cycle/X.java", + "package cycle;\n" + + "class X extends Y {}\n" + + "class Y extends X {}\n", + }, + "----------\n" + + "1. ERROR in cycle\\X.java (at line 2)\n" + + " class X extends Y {}\n" + + " ^\n" + + "The hierarchy of the type X is inconsistent\n" + + "----------\n" + + "2. ERROR in cycle\\X.java (at line 3)\n" + + " class Y extends X {}\n" + + " ^\n" + + "Cycle detected: a cycle exists in the type hierarchy between Y and X\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=319885 +public void test0014() { + this.runNegativeTest(new String[] { + "cycle/X.java", + "package cycle;\n" + + "class X extends Y {}\n" + + "class Y extends Z {}\n" + + "class Z extends A {}\n" + + "class A extends B {}\n" + + "class B extends C {}\n" + + "class C extends X {}\n" + }, + "----------\n" + + "1. ERROR in cycle\\X.java (at line 2)\n" + + " class X extends Y {}\n" + + " ^\n" + + "The hierarchy of the type X is inconsistent\n" + + "----------\n" + + "2. ERROR in cycle\\X.java (at line 3)\n" + + " class Y extends Z {}\n" + + " ^\n" + + "The hierarchy of the type Y is inconsistent\n" + + "----------\n" + + "3. ERROR in cycle\\X.java (at line 4)\n" + + " class Z extends A {}\n" + + " ^\n" + + "The hierarchy of the type Z is inconsistent\n" + + "----------\n" + + "4. ERROR in cycle\\X.java (at line 5)\n" + + " class A extends B {}\n" + + " ^\n" + + "The hierarchy of the type A is inconsistent\n" + + "----------\n" + + "5. ERROR in cycle\\X.java (at line 6)\n" + + " class B extends C {}\n" + + " ^\n" + + "The hierarchy of the type B is inconsistent\n" + + "----------\n" + + "6. ERROR in cycle\\X.java (at line 7)\n" + + " class C extends X {}\n" + + " ^\n" + + "Cycle detected: a cycle exists in the type hierarchy between C and X\n" + + "----------\n"); +} public static Class testClass() { return InnerClass15Test.class; }