Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 188509 Details for
Bug 334622
Eclipse compiler allows access to private fields for typed variables
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Revised patch under test
patch.txt (text/plain), 13.19 KB, created by
Srikanth Sankaran
on 2011-02-08 06:37:36 EST
(
hide
)
Description:
Revised patch under test
Filename:
MIME Type:
Creator:
Srikanth Sankaran
Created:
2011-02-08 06:37:36 EST
Size:
13.19 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core >Index: compiler/org/eclipse/jdt/internal/compiler/lookup/FieldBinding.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/FieldBinding.java,v >retrieving revision 1.60 >diff -u -r1.60 FieldBinding.java >--- compiler/org/eclipse/jdt/internal/compiler/lookup/FieldBinding.java 22 Oct 2010 22:42:56 -0000 1.60 >+++ compiler/org/eclipse/jdt/internal/compiler/lookup/FieldBinding.java 8 Feb 2011 11:32:01 -0000 >@@ -108,8 +108,8 @@ > // AND the invocationType and the declaringClass have a common enclosingType > receiverCheck: { > if (receiverType != this.declaringClass) { >- // special tolerance for type variable direct bounds >- if (receiverType.isTypeVariable() && ((TypeVariableBinding) receiverType).isErasureBoundTo(this.declaringClass.erasure())) >+ // special tolerance for type variable direct bounds, but only if compliance <= 1.6, see: https://bugs.eclipse.org/bugs/show_bug.cgi?id=334622 >+ if (scope.compilerOptions().complianceLevel <= ClassFileConstants.JDK1_6 && receiverType.isTypeVariable() && ((TypeVariableBinding) receiverType).isErasureBoundTo(this.declaringClass.erasure())) > break receiverCheck; > return false; > } >Index: compiler/org/eclipse/jdt/internal/compiler/lookup/MethodBinding.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodBinding.java,v >retrieving revision 1.129 >diff -u -r1.129 MethodBinding.java >--- compiler/org/eclipse/jdt/internal/compiler/lookup/MethodBinding.java 16 Jan 2011 22:43:21 -0000 1.129 >+++ compiler/org/eclipse/jdt/internal/compiler/lookup/MethodBinding.java 8 Feb 2011 11:32:02 -0000 >@@ -287,8 +287,8 @@ > // AND the invocationType and the declaringClass have a common enclosingType > receiverCheck: { > if (receiverType != this.declaringClass) { >- // special tolerance for type variable direct bounds >- if (receiverType.isTypeVariable() && ((TypeVariableBinding) receiverType).isErasureBoundTo(this.declaringClass.erasure())) >+ // special tolerance for type variable direct bounds, but only if compliance <= 1.6, see: https://bugs.eclipse.org/bugs/show_bug.cgi?id=334622 >+ if (scope.compilerOptions().complianceLevel <= ClassFileConstants.JDK1_6 && receiverType.isTypeVariable() && ((TypeVariableBinding) receiverType).isErasureBoundTo(this.declaringClass.erasure())) > break receiverCheck; > return false; > } >Index: compiler/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java,v >retrieving revision 1.140 >diff -u -r1.140 ReferenceBinding.java >--- compiler/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java 23 Dec 2010 13:57:49 -0000 1.140 >+++ compiler/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java 8 Feb 2011 11:32:02 -0000 >@@ -226,10 +226,10 @@ > // AND the invocationType and the receiver have a common enclosingType > receiverCheck: { > if (!(receiverType == this || receiverType == enclosingType())) { >- // special tolerance for type variable direct bounds >+ // special tolerance for type variable direct bounds, but only if compliance <= 1.6, see: https://bugs.eclipse.org/bugs/show_bug.cgi?id=334622 > if (receiverType.isTypeVariable()) { > TypeVariableBinding typeVariable = (TypeVariableBinding) receiverType; >- if (typeVariable.isErasureBoundTo(erasure()) || typeVariable.isErasureBoundTo(enclosingType().erasure())) >+ if (typeVariable.environment.globalOptions.complianceLevel <= ClassFileConstants.JDK1_6 && (typeVariable.isErasureBoundTo(erasure()) || typeVariable.isErasureBoundTo(enclosingType().erasure()))) > break receiverCheck; > } > return false; >#P org.eclipse.jdt.core.tests.compiler >Index: src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java,v >retrieving revision 1.826 >diff -u -r1.826 GenericTypeTest.java >--- src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java 13 Sep 2010 13:26:19 -0000 1.826 >+++ src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java 8 Feb 2011 11:32:46 -0000 >@@ -9016,6 +9016,7 @@ > "class Y extends Zork {\n" + > "}\n" > }, >+ this.complianceLevel <= ClassFileConstants.JDK1_6 ? > "----------\n" + > "1. WARNING in X.java (at line 6)\n" + > " public int foo(T t) { return t.i + t.i() + T.M.j; }\n" + >@@ -9029,6 +9030,30 @@ > "----------\n" > // 5: operator + cannot be applied to int,<any>.j > // 5: incompatible type, found : <nulltype>, required: int >+ : >+ >+ // 1.7+ output, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=334622 >+ "----------\n" + >+ "1. ERROR in X.java (at line 6)\n" + >+ " public int foo(T t) { return t.i + t.i() + T.M.j; }\n" + >+ " ^\n" + >+ "The field X<T>.i is not visible\n" + >+ "----------\n" + >+ "2. ERROR in X.java (at line 6)\n" + >+ " public int foo(T t) { return t.i + t.i() + T.M.j; }\n" + >+ " ^\n" + >+ "The method i() from the type X<T> is not visible\n" + >+ "----------\n" + >+ "3. ERROR in X.java (at line 6)\n" + >+ " public int foo(T t) { return t.i + t.i() + T.M.j; }\n" + >+ " ^^^\n" + >+ "The type T.M is not visible\n" + >+ "----------\n" + >+ "4. ERROR in X.java (at line 9)\n" + >+ " class Y extends Zork {\n" + >+ " ^^^^\n" + >+ "Zork cannot be resolved to a type\n" + >+ "----------\n" > ); > } > // https://bugs.eclipse.org/bugs/show_bug.cgi?id=72583 >@@ -49782,7 +49807,7 @@ > } > // https://bugs.eclipse.org/bugs/show_bug.cgi?id=285002 (visibility error for package private method) > public void test1458() { >- this.runConformTest( >+ this.runNegativeTest( > new String[] { > "CompilerBug.java", > "public class CompilerBug {\n" + >@@ -49806,9 +49831,36 @@ > " getClass().newInstance().privateInt = 10;\n" + > " getClass().newInstance().packagePrivateInt = 10;\n" + > " getClass().newInstance().protectedInt = 10;\n" + >+ " Zork z;\n" + > " }\n" + >- " }\n" >- }); >+ " }\n", >+ }, >+ this.complianceLevel <= ClassFileConstants.JDK1_6 ? >+ "----------\n" + >+ "1. ERROR in CompilerBug.java (at line 22)\n" + >+ " Zork z;\n" + >+ " ^^^^\n" + >+ "Zork cannot be resolved to a type\n" + >+ "----------\n" : >+ >+ // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=334622 >+ "----------\n" + >+ "1. ERROR in CompilerBug.java (at line 17)\n" + >+ " getClass().newInstance().privateMethod();\n" + >+ " ^^^^^^^^^^^^^\n" + >+ "The method privateMethod() from the type CompilerBug is not visible\n" + >+ "----------\n" + >+ "2. ERROR in CompilerBug.java (at line 19)\n" + >+ " getClass().newInstance().privateInt = 10;\n" + >+ " ^^^^^^^^^^\n" + >+ "The field CompilerBug.privateInt is not visible\n" + >+ "----------\n" + >+ "3. ERROR in CompilerBug.java (at line 22)\n" + >+ " Zork z;\n" + >+ " ^^^^\n" + >+ "Zork cannot be resolved to a type\n" + >+ "----------\n" >+ ); > } > // https://bugs.eclipse.org/bugs/show_bug.cgi?id=295698 > public void test1459() { >Index: src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest.java,v >retrieving revision 1.5 >diff -u -r1.5 GenericsRegressionTest.java >--- src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest.java 17 Dec 2010 06:40:06 -0000 1.5 >+++ src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest.java 8 Feb 2011 11:32:48 -0000 >@@ -15,6 +15,7 @@ > > import junit.framework.Test; > >+import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; > import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; > > public class GenericsRegressionTest extends AbstractComparableTest { >@@ -1157,4 +1158,150 @@ > true, > customOptions); > } >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=334622 (private access - different packages) >+public void test334622a() { >+ this.runNegativeTest( >+ new String[] { >+ "p/X.java", >+ "package p;\n" + >+ "public class X {\n" + >+ " private Object foo;\n" + >+ "}\n", >+ "q/Y.java", >+ "package q;\n" + >+ "import p.X;\n" + >+ "public class Y {\n" + >+ " public <T extends X> void test(T t) {\n" + >+ " System.out.println(t.foo);\n" + >+ " }\n" + >+ " Zork z;\n" + >+ "}\n" >+ }, >+ "----------\n" + >+ "1. WARNING in p\\X.java (at line 3)\n" + >+ " private Object foo;\n" + >+ " ^^^\n" + >+ "The value of the field X.foo is not used\n" + >+ "----------\n" + >+ "----------\n" + >+ "1. ERROR in q\\Y.java (at line 5)\n" + >+ " System.out.println(t.foo);\n" + >+ " ^^^\n" + >+ "The field X.foo is not visible\n" + >+ "----------\n" + >+ "2. ERROR in q\\Y.java (at line 7)\n" + >+ " Zork z;\n" + >+ " ^^^^\n" + >+ "Zork cannot be resolved to a type\n" + >+ "----------\n"); >+} >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=334622 (private access - same package) >+public void test334622b() { >+ this.runNegativeTest( >+ new String[] { >+ "p/X.java", >+ "package p;\n" + >+ "public class X {\n" + >+ " private Object foo;\n" + >+ "}\n", >+ "p/Y.java", >+ "package p;\n" + >+ "public class Y {\n" + >+ " public <T extends X> void test(T t) {\n" + >+ " System.out.println(t.foo);\n" + >+ " }\n" + >+ " Zork z;\n" + >+ "}\n" >+ }, >+ "----------\n" + >+ "1. WARNING in p\\X.java (at line 3)\n" + >+ " private Object foo;\n" + >+ " ^^^\n" + >+ "The value of the field X.foo is not used\n" + >+ "----------\n" + >+ "----------\n" + >+ "1. ERROR in p\\Y.java (at line 4)\n" + >+ " System.out.println(t.foo);\n" + >+ " ^^^\n" + >+ "The field X.foo is not visible\n" + >+ "----------\n" + >+ "2. ERROR in p\\Y.java (at line 6)\n" + >+ " Zork z;\n" + >+ " ^^^^\n" + >+ "Zork cannot be resolved to a type\n" + >+ "----------\n"); >+} >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=334622 (member of type variable shouldn't contain private members of class constituting intersection type) >+public void test334622c() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " private Object foo;\n" + >+ " public <T extends X> void test(T t) {\n" + >+ " System.out.println(t.foo);\n" + >+ " Zork z;\n" + >+ " }\n" + >+ "}\n" >+ }, >+ this.complianceLevel <= ClassFileConstants.JDK1_6 ? >+ "----------\n" + >+ "1. ERROR in X.java (at line 5)\n" + >+ " Zork z;\n" + >+ " ^^^^\n" + >+ "Zork cannot be resolved to a type\n" + >+ "----------\n" : >+ >+ // 1.7+ output. >+ "----------\n" + >+ "1. WARNING in X.java (at line 2)\n" + >+ " private Object foo;\n" + >+ " ^^^\n" + >+ "The value of the field X.foo is not used\n" + >+ "----------\n" + >+ "2. ERROR in X.java (at line 4)\n" + >+ " System.out.println(t.foo);\n" + >+ " ^^^\n" + >+ "The field X.foo is not visible\n" + >+ "----------\n" + >+ "3. ERROR in X.java (at line 5)\n" + >+ " Zork z;\n" + >+ " ^^^^\n" + >+ "Zork cannot be resolved to a type\n" + >+ "----------\n"); >+} >+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=334622 (member of type variable shouldn't contain private members of class constituting intersection type) >+public void test334622d() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " private Object foo() { return null; }\n" + >+ " public <T extends X> void test(T t) {\n" + >+ " t.foo();\n" + >+ " Zork z;\n" + >+ " }\n" + >+ "}\n" >+ }, >+ this.complianceLevel <= ClassFileConstants.JDK1_6 ? >+ "----------\n" + >+ "1. ERROR in X.java (at line 5)\n" + >+ " Zork z;\n" + >+ " ^^^^\n" + >+ "Zork cannot be resolved to a type\n" + >+ "----------\n" : >+ >+ // 1.7+ output. >+ "----------\n" + >+ "1. ERROR in X.java (at line 4)\n" + >+ " t.foo();\n" + >+ " ^^^\n" + >+ "The method foo() from the type X is not visible\n" + >+ "----------\n" + >+ "2. ERROR in X.java (at line 5)\n" + >+ " Zork z;\n" + >+ " ^^^^\n" + >+ "Zork cannot be resolved to a type\n" + >+ "----------\n"); >+} > } >\ No newline at end of file
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 334622
:
188502
| 188509