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 188502 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]
Patch under consideration
patch.txt (text/plain), 8.08 KB, created by
Srikanth Sankaran
on 2011-02-08 05:20:15 EST
(
hide
)
Description:
Patch under consideration
Filename:
MIME Type:
Creator:
Srikanth Sankaran
Created:
2011-02-08 05:20:15 EST
Size:
8.08 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 10:19:27 -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 below 1.7 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 10:19:27 -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; > } >#P org.eclipse.jdt.core.tests.compiler >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 10:19:30 -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