### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: compiler/org/eclipse/jdt/internal/compiler/ast/ASTNode.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ASTNode.java,v retrieving revision 1.58 diff -u -r1.58 ASTNode.java --- compiler/org/eclipse/jdt/internal/compiler/ast/ASTNode.java 10 Jan 2006 21:01:06 -0000 1.58 +++ compiler/org/eclipse/jdt/internal/compiler/ast/ASTNode.java 13 Jan 2006 10:45:57 -0000 @@ -7,6 +7,8 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Matt McCutchen + * Partial fix for https://bugs.eclipse.org/bugs/show_bug.cgi?id=122995. *******************************************************************************/ package org.eclipse.jdt.internal.compiler.ast; @@ -268,7 +270,7 @@ if ((field.modifiers & ExtraCompilerModifiers.AccRestrictedAccess) != 0) { AccessRestriction restriction = - scope.environment().getAccessRestriction(field.declaringClass); + scope.environment().getAccessRestriction(field.declaringClass.erasure()); if (restriction != null) { scope.problemReporter().forbiddenReference(field, this, restriction.getFieldAccessMessageTemplate(), restriction.getProblemId()); @@ -306,7 +308,7 @@ // note: explicit constructors calls warnings are kept despite the 'new C1()' case (two // warnings, one on type, the other on constructor), because of the 'super()' case. AccessRestriction restriction = - scope.environment().getAccessRestriction(method.declaringClass); + scope.environment().getAccessRestriction(method.declaringClass.erasure()); if (restriction != null) { if (method.isConstructor()) { scope.problemReporter().forbiddenReference(method, this, @@ -365,7 +367,7 @@ } if (refType.hasRestrictedAccess()) { - AccessRestriction restriction = scope.environment().getAccessRestriction(type); + AccessRestriction restriction = scope.environment().getAccessRestriction(type.erasure()); if (restriction != null) { scope.problemReporter().forbiddenReference(type, this, restriction.getMessageTemplate(), restriction.getProblemId()); } Index: buildnotes_jdt-core.html =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/buildnotes_jdt-core.html,v retrieving revision 1.4851 diff -u -r1.4851 buildnotes_jdt-core.html --- buildnotes_jdt-core.html 13 Jan 2006 09:19:07 -0000 1.4851 +++ buildnotes_jdt-core.html 13 Jan 2006 10:45:57 -0000 @@ -57,7 +57,9 @@

Problem Reports Fixed

-123721 +122995 +[1.5][compiler] Access rules don't apply to generic types +
123721 two types of 'remove' for TODO task tags
123396 Regression: NameLookup creation longs around 1mn on project with heavy hiearchy (200 src folders * 200 packages) #P org.eclipse.jdt.core.tests.compiler Index: src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java,v retrieving revision 1.30 diff -u -r1.30 BatchCompilerTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java 4 Jan 2006 16:06:24 -0000 1.30 +++ src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java 13 Jan 2006 10:46:00 -0000 @@ -2121,6 +2121,77 @@ true); } +// Missing access restriction violation error on generic type. +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=122995 +// Binary case. +public void test039(){ + this.runConformTest( + new String[] { + "src1/p/X.java", + "package p;\n" + + "public class X {\n" + + " T m;\n" + + "}", + }, + "\"" + OUTPUT_DIR + "/src1/p/X.java\"" + + " -1.5 -g -preserveAllLocals" + + " -proceedOnError -referenceInfo" + + " -d \"" + OUTPUT_DIR + "/bin1/\"", + "", + "", + true); + this.runConformTest( + new String[] { + "src2/Y.java", + "package p;\n" + + "public class Y {\n" + + " X x1;\n" + + " X x2 = new X();\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "src2/Y.java\"" + + " -1.5 -g -preserveAllLocals" + + " -cp \"" + OUTPUT_DIR + File.separator + "bin1[~**/X]\"" + + " -proceedOnError -referenceInfo" + + " -d \"" + OUTPUT_DIR + File.separator + "bin2/\"", + "", + "----------\n" + + "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---" + + File.separator + "src2" + + File.separator + "Y.java\n" + + " (at line 3)\n" + + " X x1;\n" + + " ^\n" + + "Discouraged access: X\n" + + "----------\n" + + "2. WARNING in ---OUTPUT_DIR_PLACEHOLDER---" + + File.separator + "src2" + + File.separator + "Y.java\n" + + " (at line 4)\n" + + " X x2 = new X();\n" + + " ^\n" + + "Discouraged access: X\n" + + "----------\n" + + "3. WARNING in ---OUTPUT_DIR_PLACEHOLDER---" + + File.separator + "src2" + + File.separator + "Y.java\n" + + " (at line 4)\n" + + " X x2 = new X();\n" + + " ^^^^^^^^^^^^^^^\n" + + "Discouraged access: X()\n" + + "----------\n" + + "4. WARNING in ---OUTPUT_DIR_PLACEHOLDER---" + + File.separator + "src2" + + File.separator + "Y.java\n" + + " (at line 4)\n" + + " X x2 = new X();\n" + + " ^\n" + + "Discouraged access: X\n" + + "----------\n" + + "4 problems (4 warnings)", + false); +} + public static Class testClass() { return BatchCompilerTest.class; } #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/model/AccessRestrictionsTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AccessRestrictionsTests.java,v retrieving revision 1.3 diff -u -r1.3 AccessRestrictionsTests.java --- src/org/eclipse/jdt/core/tests/model/AccessRestrictionsTests.java 6 Jan 2006 12:58:26 -0000 1.3 +++ src/org/eclipse/jdt/core/tests/model/AccessRestrictionsTests.java 13 Jan 2006 10:46:04 -0000 @@ -539,4 +539,490 @@ deleteProjects(new String[] {"P1", "P2"}); } } + +/* + * Missing access restriction violation error on generic type. + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=122995 + */ +public void test006() throws CoreException { + ICompilationUnit x = null, y = null; + try { + WorkingCopyOwner owner = new WorkingCopyOwner(){}; + IJavaProject p1 = createJavaProject( + "P1", + new String[] {"src"}, + new String[] {"JCL_LIB"}, + "bin"); + p1.setOption("org.eclipse.jdt.core.compiler.compliance", "1.5"); + p1.setOption("org.eclipse.jdt.core.compiler.source", "1.5"); + p1.setOption("org.eclipse.jdt.core.compiler.targetPlatform", "1.5"); + this.problemRequestor = new ProblemRequestor(); + x = getWorkingCopy( + "/P1/src/p/X.java", + "package p;\n" + + "public class X {\n" + + " T m;\n" + + "}", + owner, + this.problemRequestor); + assertProblems( + "Unexpected problems", + "----------\n" + + "----------\n" + ); + IJavaProject p2 = createJavaProject( + "P2", + new String[] {"src"}, + new String[] {"JCL_LIB"}, + "bin"); + p2.setOption("org.eclipse.jdt.core.compiler.compliance", "1.5"); + p2.setOption("org.eclipse.jdt.core.compiler.source", "1.5"); + p2.setOption("org.eclipse.jdt.core.compiler.targetPlatform", "1.5"); + IClasspathEntry[] classpath = p2.getRawClasspath(); + int length = classpath.length; + System.arraycopy(classpath, 0, classpath = new IClasspathEntry[length+1], 0, length); + classpath[length] = createSourceEntry("P2", "/P1", "-p/X"); + p2.setRawClasspath(classpath, null); + String src = + "package p;\n" + + "public class Y {\n" + + " X x1;\n" + + " X x2 = new X();\n" + + "}"; + this.problemRequestor = new ProblemRequestor(src); + y = getWorkingCopy( + "/P2/src/p/Y.java", + src, + owner, + this.problemRequestor); + assertProblems( + "Unexpected problems value", + "----------\n" + + "1. ERROR in /P2/src/p/Y.java (at line 3)\n" + + " X x1;\n" + + " ^\n" + + "Access restriction: The type X is not accessible due to restriction on required project P1\n" + + "----------\n" + + "2. ERROR in /P2/src/p/Y.java (at line 4)\n" + + " X x2 = new X();\n" + + " ^\n" + + "Access restriction: The type X is not accessible due to restriction on required project P1\n" + + "----------\n" + + "3. ERROR in /P2/src/p/Y.java (at line 4)\n" + + " X x2 = new X();\n" + + " ^^^^^^^^^^^^^^^\n" + + "Access restriction: The constructor X() is not accessible due to restriction on required project P1\n" + + "----------\n" + + "4. ERROR in /P2/src/p/Y.java (at line 4)\n" + + " X x2 = new X();\n" + + " ^\n" + + "Access restriction: The type X is not accessible due to restriction on required project P1\n" + + "----------\n"); + } finally { + if (x != null) { + x.discardWorkingCopy(); + } + if (y != null) { + y.discardWorkingCopy(); + } + deleteProjects(new String[] {"P1", "P2"}); + } +} + +/* + * Missing access restriction violation error on generic type. + * More complex type parameter - stretch the erasure. + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=122995 + */ +public void test007() throws CoreException { + ICompilationUnit x = null, y = null; + try { + WorkingCopyOwner owner = new WorkingCopyOwner(){}; + IJavaProject p1 = createJavaProject( + "P1", + new String[] {"src"}, + new String[] {"JCL_LIB"}, + "bin"); + p1.setOption("org.eclipse.jdt.core.compiler.compliance", "1.5"); + p1.setOption("org.eclipse.jdt.core.compiler.source", "1.5"); + p1.setOption("org.eclipse.jdt.core.compiler.targetPlatform", "1.5"); + this.problemRequestor = new ProblemRequestor(); + x = getWorkingCopy( + "/P1/src/p/X.java", + "package p;\n" + + "public class X {\n" + + " T m;\n" + + " public X (T t) {\n" + + " this.m = t;\n" + + " }\n" + + "}", + owner, + this.problemRequestor); + assertProblems( + "Unexpected problems", + "----------\n" + + "----------\n" + ); + IJavaProject p2 = createJavaProject( + "P2", + new String[] {"src"}, + new String[] {"JCL_LIB"}, + "bin"); + p2.setOption("org.eclipse.jdt.core.compiler.compliance", "1.5"); + p2.setOption("org.eclipse.jdt.core.compiler.source", "1.5"); + p2.setOption("org.eclipse.jdt.core.compiler.targetPlatform", "1.5"); + IClasspathEntry[] classpath = p2.getRawClasspath(); + int length = classpath.length; + System.arraycopy(classpath, 0, classpath = new IClasspathEntry[length+1], 0, length); + classpath[length] = createSourceEntry("P2", "/P1", "-p/X"); + p2.setRawClasspath(classpath, null); + String src = + "package p;\n" + + "public class Y {\n" + + " X x1;\n" + + " X x2 = new X(\"\");\n" + + "}"; + this.problemRequestor = new ProblemRequestor(src); + y = getWorkingCopy( + "/P2/src/p/Y.java", + src, + owner, + this.problemRequestor); + assertProblems( + "Unexpected problems value", + "----------\n" + + "1. ERROR in /P2/src/p/Y.java (at line 3)\n" + + " X x1;\n" + + " ^\n" + + "Access restriction: The type X is not accessible due to restriction on required project P1\n" + + "----------\n" + + "2. ERROR in /P2/src/p/Y.java (at line 4)\n" + + " X x2 = new X(\"\");\n" + + " ^\n" + + "Access restriction: The type X is not accessible due to restriction on required project P1\n" + + "----------\n" + + "3. ERROR in /P2/src/p/Y.java (at line 4)\n" + + " X x2 = new X(\"\");\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Access restriction: The constructor X(String) is not accessible due to restriction on required project P1\n" + + "----------\n" + + "4. ERROR in /P2/src/p/Y.java (at line 4)\n" + + " X x2 = new X(\"\");\n" + + " ^\n" + + "Access restriction: The type X is not accessible due to restriction on required project P1\n" + + "----------\n"); + } finally { + if (x != null) { + x.discardWorkingCopy(); + } + if (y != null) { + y.discardWorkingCopy(); + } + deleteProjects(new String[] {"P1", "P2"}); + } +} + +/* + * Missing access restriction violation error on generic type. + * Method case. + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=122995 + */ +public void test008() throws CoreException { + ICompilationUnit x1 = null, x2 = null, y = null; + try { + WorkingCopyOwner owner = new WorkingCopyOwner(){}; + IJavaProject p1 = createJavaProject( + "P1", + new String[] {"src"}, + new String[] {"JCL_LIB"}, + "bin"); + p1.setOption("org.eclipse.jdt.core.compiler.compliance", "1.5"); + p1.setOption("org.eclipse.jdt.core.compiler.source", "1.5"); + p1.setOption("org.eclipse.jdt.core.compiler.targetPlatform", "1.5"); + this.problemRequestor = new ProblemRequestor(); + x1 = getWorkingCopy( + "/P1/src/p/X1.java", + "package p;\n" + + "public class X1 {\n" + + " void foo() {\n" + + " }\n" + + "}", + owner, + this.problemRequestor); + assertProblems( + "Unexpected problems", + "----------\n" + + "----------\n" + ); + x2 = getWorkingCopy( + "/P1/src/p/X2.java", + "package p;\n" + + "public class X2 extends X1 {\n" + + " void bar() {\n" + + " }\n" + + "}", owner, + this.problemRequestor); + assertProblems( + "Unexpected problems", + "----------\n" + + "----------\n" + ); + IJavaProject p2 = createJavaProject("P2", new String[] {"src"}, + new String[] {"JCL_LIB"}, "bin"); + p2.setOption("org.eclipse.jdt.core.compiler.compliance", "1.5"); + p2.setOption("org.eclipse.jdt.core.compiler.source", "1.5"); + p2.setOption("org.eclipse.jdt.core.compiler.targetPlatform", "1.5"); + IClasspathEntry[] classpath = p2.getRawClasspath(); + int length = classpath.length; + System.arraycopy(classpath, 0, classpath = new IClasspathEntry[length+1], 0, length); + classpath[length] = createSourceEntry("P2", "/P1", "-p/X1"); + p2.setRawClasspath(classpath, null); + String src = + "package p;\n" + + "public class Y extends X2 {\n" + + " void foobar() {\n" + + " foo(); // accesses X1.foo, should trigger an error\n" + + " bar(); // accesses X2.bar, OK\n" + + " }\n" + + "}"; + this.problemRequestor = new ProblemRequestor(src); + y = getWorkingCopy( + "/P2/src/p/Y.java", + src, + owner, + this.problemRequestor); + assertProblems( + "Unexpected problems value", + "----------\n" + + "1. ERROR in /P2/src/p/Y.java (at line 4)\n" + + " foo(); // accesses X1.foo, should trigger an error\n" + + " ^^^^^\n" + + "Access restriction: The method foo() from the type X1 is not accessible due to restriction on required project P1\n" + + "----------\n" + ); + } finally { + if (x1 != null) + x1.discardWorkingCopy(); + if (x2 != null) + x2.discardWorkingCopy(); + if (y != null) + y.discardWorkingCopy(); + deleteProjects(new String[] {"P1", "P2"}); + } +} + +/* + * Missing access restriction violation error on generic type. + * Field case. + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=122995 + */ +public void test009() throws CoreException { + ICompilationUnit x1 = null, x2 = null, y = null; + try { + WorkingCopyOwner owner = new WorkingCopyOwner(){}; + IJavaProject p1 = createJavaProject( + "P1", + new String[] {"src"}, + new String[] {"JCL_LIB"}, + "bin"); + p1.setOption("org.eclipse.jdt.core.compiler.compliance", "1.5"); + p1.setOption("org.eclipse.jdt.core.compiler.source", "1.5"); + p1.setOption("org.eclipse.jdt.core.compiler.targetPlatform", "1.5"); + this.problemRequestor = new ProblemRequestor(); + x1 = getWorkingCopy( + "/P1/src/p/X1.java", + "package p;\n" + + "public class X1 {\n" + + " int m1;\n" + + "}", + owner, + this.problemRequestor); + assertProblems( + "Unexpected problems", + "----------\n" + + "----------\n" + ); + x2 = getWorkingCopy( + "/P1/src/p/X2.java", + "package p;\n" + + "public class X2 extends X1 {\n" + + " char m2;\n" + + "}", + owner, + this.problemRequestor); + assertProblems( + "Unexpected problems", + "----------\n" + + "----------\n" + ); + IJavaProject p2 = createJavaProject("P2", new String[] {"src"}, + new String[] {"JCL_LIB"}, "bin"); + p2.setOption("org.eclipse.jdt.core.compiler.compliance", "1.5"); + p2.setOption("org.eclipse.jdt.core.compiler.source", "1.5"); + p2.setOption("org.eclipse.jdt.core.compiler.targetPlatform", "1.5"); + IClasspathEntry[] classpath = p2.getRawClasspath(); + int length = classpath.length; + System.arraycopy(classpath, 0, classpath = new IClasspathEntry[length+1], 0, length); + classpath[length] = createSourceEntry("P2", "/P1", "-p/X1"); + p2.setRawClasspath(classpath, null); + String src = + "package p;\n" + + "public class Y extends X2 {\n" + + " void foobar() {\n" + + " int l1 = m1; // accesses X1.m1, should trigger an error\n" + + " char l2 = m2; // accesses X2.m2, OK\n" + + " }\n" + + "}"; + this.problemRequestor = new ProblemRequestor(src); + y = getWorkingCopy( + "/P2/src/p/Y.java", + src, + owner, + this.problemRequestor); + assertProblems( + "Unexpected problems value", + "----------\n" + + "1. ERROR in /P2/src/p/Y.java (at line 4)\n" + + " int l1 = m1; // accesses X1.m1, should trigger an error\n" + + " ^^\n" + + "Access restriction: The field m1 from the type X1 is not accessible due to restriction on required project P1\n" + + "----------\n" + ); + } finally { + if (x1 != null) + x1.discardWorkingCopy(); + if (x2 != null) + x2.discardWorkingCopy(); + if (y != null) + y.discardWorkingCopy(); + deleteProjects(new String[] {"P1", "P2"}); + } +} + +/* + * Missing access restriction violation error on generic type. + * Inner type case. + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=122995 + */ +public void test010() throws CoreException { + ICompilationUnit x1 = null, x2 = null, y = null; + try { + WorkingCopyOwner owner = new WorkingCopyOwner(){}; + IJavaProject p1 = createJavaProject( + "P1", + new String[] {"src"}, + new String[] {"JCL_LIB"}, + "bin"); + p1.setOption("org.eclipse.jdt.core.compiler.compliance", "1.5"); + p1.setOption("org.eclipse.jdt.core.compiler.source", "1.5"); + p1.setOption("org.eclipse.jdt.core.compiler.targetPlatform", "1.5"); + this.problemRequestor = new ProblemRequestor(); + x1 = getWorkingCopy( + "/P1/src/p/X1.java", + "package p;\n" + + "public class X1 {\n" + + " class C1 {\n" + + " protected C1 (int dummy) {}\n" + + " protected void foo() {}\n" + + " }\n" + + " interface I1 {}\n" + + "}", + owner, + this.problemRequestor); + assertProblems( + "Unexpected problems", + "----------\n" + + "----------\n" + ); + x2 = getWorkingCopy( + "/P1/src/p/X2.java", + "package p;\n" + + "public class X2 extends X1 {\n" + + " class C2 {}\n" + + " interface I2 {}\n" + + "}", + owner, + this.problemRequestor); + assertProblems( + "Unexpected problems", + "----------\n" + + "----------\n" + ); + IJavaProject p2 = createJavaProject("P2", new String[] {"src"}, + new String[] {"JCL_LIB"}, "bin"); + p2.setOption("org.eclipse.jdt.core.compiler.compliance", "1.5"); + p2.setOption("org.eclipse.jdt.core.compiler.source", "1.5"); + p2.setOption("org.eclipse.jdt.core.compiler.targetPlatform", "1.5"); + IClasspathEntry[] classpath = p2.getRawClasspath(); + int length = classpath.length; + System.arraycopy(classpath, 0, classpath = new IClasspathEntry[length+1], 0, length); + classpath[length] = createSourceEntry("P2", "/P1", "-p/X1"); + p2.setRawClasspath(classpath, null); + String src = + "package p;\n" + + "public class Y extends X2 {\n" + + " class C3a extends C1 { // error\n" + + " C3a() {\n" + + " super(0);\n" + + " foo(); // error\n" + + " }\n" + + " }\n" + + " class C3c extends C2 implements I2 {}\n" + + " void foobar() {\n" + + " C1 m1 = // error\n" + + " new C1(0); // error\n" + + " C2 m2 = new C2();\n" + + " }\n" + + "}"; + this.problemRequestor = new ProblemRequestor(src); + y = getWorkingCopy( + "/P2/src/p/Y.java", + src, + owner, + this.problemRequestor); + assertProblems( + "Unexpected problems value", + "----------\n" + + "1. ERROR in /P2/src/p/Y.java (at line 3)\n" + + " class C3a extends C1 { // error\n" + + " ^^\n" + + "Access restriction: The type X1.C1 is not accessible due to restriction on required project P1\n" + + "----------\n" + + "2. ERROR in /P2/src/p/Y.java (at line 5)\n" + + " super(0);\n" + + " ^^^^^^^^\n" + + "Access restriction: The constructor X1.C1(int) is not accessible due to restriction on required project P1\n" + + "----------\n" + + "3. ERROR in /P2/src/p/Y.java (at line 6)\n" + + " foo(); // error\n" + + " ^^^^^\n" + + "Access restriction: The method foo() from the type X1.C1 is not accessible due to restriction on required project P1\n" + + "----------\n" + + "4. ERROR in /P2/src/p/Y.java (at line 11)\n" + + " C1 m1 = // error\n" + + " ^^\n" + + "Access restriction: The type X1.C1 is not accessible due to restriction on required project P1\n" + + "----------\n" + + "5. ERROR in /P2/src/p/Y.java (at line 12)\n" + + " new C1(0); // error\n" + + " ^^^^^^^^^\n" + + "Access restriction: The constructor X1.C1(int) is not accessible due to restriction on required project P1\n" + + "----------\n" + + "6. ERROR in /P2/src/p/Y.java (at line 12)\n" + + " new C1(0); // error\n" + + " ^^\n" + + "Access restriction: The type X1.C1 is not accessible due to restriction on required project P1\n" + + "----------\n" + ); + } finally { + if (x1 != null) + x1.discardWorkingCopy(); + if (x2 != null) + x2.discardWorkingCopy(); + if (y != null) + y.discardWorkingCopy(); + deleteProjects(new String[] {"P1", "P2"}); + } +} + }