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 172992 Details for
Bug 318171
fieldHiding-Warning does not appear if classes are in different packages
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Revised patch with remastered tests.
patch.txt (text/plain), 12.90 KB, created by
Srikanth Sankaran
on 2010-06-29 07:15:27 EDT
(
hide
)
Description:
Revised patch with remastered tests.
Filename:
MIME Type:
Creator:
Srikanth Sankaran
Created:
2010-06-29 07:15:27 EDT
Size:
12.90 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core >Index: compiler/org/eclipse/jdt/internal/compiler/ast/FieldDeclaration.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/FieldDeclaration.java,v >retrieving revision 1.100 >diff -u -r1.100 FieldDeclaration.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/FieldDeclaration.java 7 Jan 2010 20:18:49 -0000 1.100 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/FieldDeclaration.java 29 Jun 2010 11:14:21 -0000 >@@ -150,7 +150,10 @@ > SourceTypeBinding declaringType = classScope.enclosingSourceType(); > checkHidingSuperField: { > if (declaringType.superclass == null) break checkHidingSuperField; >- FieldBinding existingVariable = classScope.findField(declaringType.superclass, this.name, this, false /*do not resolve hidden field*/); >+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=318171, find field skipping visibility checks >+ // we do the checks below ourselves, using the appropriate conditions for access check of >+ // protected members from superclasses. >+ FieldBinding existingVariable = classScope.findField(declaringType.superclass, this.name, this, false /*do not resolve hidden field*/, true /* no visibility checks please */); > if (existingVariable == null) break checkHidingSuperField; // keep checking outer scenario > if (!existingVariable.isValidBinding()) break checkHidingSuperField; // keep checking outer scenario > if (existingVariable.original() == this.binding) break checkHidingSuperField; // keep checking outer scenario >Index: compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java,v >retrieving revision 1.369 >diff -u -r1.369 Scope.java >--- compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java 22 Jun 2010 02:31:06 -0000 1.369 >+++ compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java 29 Jun 2010 11:14:23 -0000 >@@ -934,6 +934,9 @@ > return null; > } > >+ public FieldBinding findField(TypeBinding receiverType, char[] fieldName, InvocationSite invocationSite, boolean needResolve) { >+ return findField(receiverType, fieldName, invocationSite, needResolve, false); >+ } > // Internal use only > /* Answer the field binding that corresponds to fieldName. > Start the lookup at the receiverType. >@@ -941,10 +944,11 @@ > isSuperAccess(); this is used to determine if the discovered field is visible. > Only fields defined by the receiverType or its supertypes are answered; > a field of an enclosing type will not be found using this API. >- >+ If the parameter invisibleFieldsOk is true, visibility checks have not been run on >+ any returned fields. The caller needs to apply these checks as needed. Otherwise, > If no visible field is discovered, null is answered. > */ >- public FieldBinding findField(TypeBinding receiverType, char[] fieldName, InvocationSite invocationSite, boolean needResolve) { >+ public FieldBinding findField(TypeBinding receiverType, char[] fieldName, InvocationSite invocationSite, boolean needResolve, boolean invisibleFieldsOk) { > > CompilationUnitScope unitScope = compilationUnitScope(); > unitScope.recordTypeReference(receiverType); >@@ -989,6 +993,9 @@ > // https://bugs.eclipse.org/bugs/show_bug.cgi?id=316456 > boolean insideTypeAnnotations = this instanceof MethodScope && ((MethodScope) this).insideTypeAnnotation; > if (field != null) { >+ if (invisibleFieldsOk) { >+ return field; >+ } > if (invocationSite == null || insideTypeAnnotations > ? field.canBeSeenBy(getCurrentPackage()) > : field.canBeSeenBy(currentType, invocationSite, this)) >@@ -1027,6 +1034,9 @@ > currentType.initializeForStaticImports(); > currentType = (ReferenceBinding) currentType.capture(this, invocationSite == null ? 0 : invocationSite.sourceEnd()); > if ((field = currentType.getField(fieldName, needResolve)) != null) { >+ if (invisibleFieldsOk) { >+ return field; >+ } > keepLooking = false; > if (field.canBeSeenBy(receiverType, invocationSite, this)) { > if (visibleField == null) >@@ -1048,6 +1058,9 @@ > unitScope.recordTypeReference(anInterface); > // no need to capture rcv interface, since member field is going to be static anyway > if ((field = anInterface.getField(fieldName, true /*resolve*/)) != null) { >+ if (invisibleFieldsOk) { >+ return field; >+ } > if (visibleField == null) { > visibleField = field; > } else { >#P org.eclipse.jdt.core.tests.compiler >Index: src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_3.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_3.java,v >retrieving revision 1.106 >diff -u -r1.106 Compliance_1_3.java >--- src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_3.java 3 Mar 2010 18:18:55 -0000 1.106 >+++ src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_3.java 29 Jun 2010 11:14:29 -0000 >@@ -1028,16 +1028,22 @@ > " String bar = \"X2.bar\"; \n" + > "} \n", > }, >- "----------\n" + >- "1. ERROR in p\\X.java (at line 4)\n" + >- " System.out.println(new q.X2().foo); \n" + >- " ^^^\n" + >- "The field X2.foo is not visible\n" + >- "----------\n" + >- "2. ERROR in p\\X.java (at line 5)\n" + >- " System.out.println(new q.X2().bar); \n" + >- " ^^^\n" + >- "The field X2.bar is not visible\n" + >+ "----------\n" + >+ "1. ERROR in p\\X.java (at line 4)\n" + >+ " System.out.println(new q.X2().foo); \n" + >+ " ^^^\n" + >+ "The field X2.foo is not visible\n" + >+ "----------\n" + >+ "2. ERROR in p\\X.java (at line 5)\n" + >+ " System.out.println(new q.X2().bar); \n" + >+ " ^^^\n" + >+ "The field X2.bar is not visible\n" + >+ "----------\n" + >+ "----------\n" + >+ "1. WARNING in q\\X2.java (at line 3)\n" + >+ " protected String foo = \"X2.foo\"; \n" + >+ " ^^^\n" + >+ "The field X2.foo is hiding a field from type X1\n" + > "----------\n"); > } > /* >Index: src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_4.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_4.java,v >retrieving revision 1.107 >diff -u -r1.107 Compliance_1_4.java >--- src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_4.java 3 Mar 2010 18:19:01 -0000 1.107 >+++ src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_4.java 29 Jun 2010 11:14:31 -0000 >@@ -1015,16 +1015,22 @@ > " String bar = \"X2.bar\"; \n" + > "} \n", > }, >- "----------\n" + >- "1. ERROR in p\\X.java (at line 4)\n" + >- " System.out.println(new q.X2().foo); \n" + >- " ^^^\n" + >- "The field X2.foo is not visible\n" + >- "----------\n" + >- "2. ERROR in p\\X.java (at line 5)\n" + >- " System.out.println(new q.X2().bar); \n" + >- " ^^^\n" + >- "The field X2.bar is not visible\n" + >+ "----------\n" + >+ "1. ERROR in p\\X.java (at line 4)\n" + >+ " System.out.println(new q.X2().foo); \n" + >+ " ^^^\n" + >+ "The field X2.foo is not visible\n" + >+ "----------\n" + >+ "2. ERROR in p\\X.java (at line 5)\n" + >+ " System.out.println(new q.X2().bar); \n" + >+ " ^^^\n" + >+ "The field X2.bar is not visible\n" + >+ "----------\n" + >+ "----------\n" + >+ "1. WARNING in q\\X2.java (at line 3)\n" + >+ " protected String foo = \"X2.foo\"; \n" + >+ " ^^^\n" + >+ "The field X2.foo is hiding a field from type X1\n" + > "----------\n"); > } > >Index: src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_5.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_5.java,v >retrieving revision 1.86 >diff -u -r1.86 Compliance_1_5.java >--- src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_5.java 3 Mar 2010 18:18:49 -0000 1.86 >+++ src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_5.java 29 Jun 2010 11:14:33 -0000 >@@ -1032,16 +1032,22 @@ > " String bar = \"X2.bar\"; \n" + > "} \n", > }, >- "----------\n" + >- "1. ERROR in p\\X.java (at line 4)\n" + >- " System.out.println(new q.X2().foo); \n" + >- " ^^^\n" + >- "The field X2.foo is not visible\n" + >- "----------\n" + >- "2. ERROR in p\\X.java (at line 5)\n" + >- " System.out.println(new q.X2().bar); \n" + >- " ^^^\n" + >- "The field X2.bar is not visible\n" + >+ "----------\n" + >+ "1. ERROR in p\\X.java (at line 4)\n" + >+ " System.out.println(new q.X2().foo); \n" + >+ " ^^^\n" + >+ "The field X2.foo is not visible\n" + >+ "----------\n" + >+ "2. ERROR in p\\X.java (at line 5)\n" + >+ " System.out.println(new q.X2().bar); \n" + >+ " ^^^\n" + >+ "The field X2.bar is not visible\n" + >+ "----------\n" + >+ "----------\n" + >+ "1. WARNING in q\\X2.java (at line 3)\n" + >+ " protected String foo = \"X2.foo\"; \n" + >+ " ^^^\n" + >+ "The field X2.foo is hiding a field from type X1\n" + > "----------\n"); > } > >Index: src/org/eclipse/jdt/core/tests/compiler/regression/FieldAccessTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/FieldAccessTest.java,v >retrieving revision 1.11 >diff -u -r1.11 FieldAccessTest.java >--- src/org/eclipse/jdt/core/tests/compiler/regression/FieldAccessTest.java 11 May 2010 18:53:50 -0000 1.11 >+++ src/org/eclipse/jdt/core/tests/compiler/regression/FieldAccessTest.java 29 Jun 2010 11:14:33 -0000 >@@ -679,6 +679,95 @@ > "OLD_FIELD cannot be resolved or is not a field\n" + > "----------\n"); > } >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=318171 >+public void test023() { >+ this.runNegativeTest( >+ new String[] { >+ "p1/A.java", >+ "package p1;\n" + >+ "public abstract class A {\n" + >+ " protected int field;\n" + >+ "}\n", >+ "p2/B.java", >+ "package p2;\n" + >+ "import p1.A;\n" + >+ "public abstract class B extends A {\n" + >+ " protected int field;\n" + >+ "}\n" >+ }, >+ "----------\n" + >+ "1. WARNING in p2\\B.java (at line 4)\n" + >+ " protected int field;\n" + >+ " ^^^^^\n" + >+ "The field B.field is hiding a field from type A\n" + >+ "----------\n"); >+} >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=318171 >+public void test024() { >+ this.runNegativeTest( >+ new String[] { >+ "p1/A.java", >+ "package p1;\n" + >+ "public abstract class A extends Super {\n" + >+ "}\n", >+ "p1/Super.java", >+ "package p1;\n" + >+ "public abstract class Super extends SuperSuper {\n" + >+ "}\n", >+ "p1/SuperSuper.java", >+ "package p1;\n" + >+ "public abstract class SuperSuper {\n" + >+ " protected int field;\n" + >+ "}\n", >+ "p2/B.java", >+ "package p2;\n" + >+ "import p1.A;\n" + >+ "public abstract class B extends A {\n" + >+ " protected int field;\n" + >+ "}\n" >+ }, >+ "----------\n" + >+ "1. WARNING in p2\\B.java (at line 4)\n" + >+ " protected int field;\n" + >+ " ^^^^^\n" + >+ "The field B.field is hiding a field from type SuperSuper\n" + >+ "----------\n"); >+} >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=318171 >+public void test025() { >+ this.runNegativeTest( >+ new String[] { >+ "p1/A.java", >+ "package p1;\n" + >+ "public abstract class A extends Super {\n" + >+ "}\n", >+ "p1/Super.java", >+ "package p1;\n" + >+ "public abstract class Super extends SuperSuper {\n" + >+ "}\n", >+ "p1/SuperSuper.java", >+ "package p1;\n" + >+ "public abstract class SuperSuper implements Interface{\n" + >+ "}\n", >+ "p1/Interface.java", >+ "package p1;\n" + >+ "public interface Interface{\n" + >+ " int field = 123;\n" + >+ "}\n", >+ "p2/B.java", >+ "package p2;\n" + >+ "import p1.A;\n" + >+ "public abstract class B extends A {\n" + >+ " protected int field;\n" + >+ "}\n" >+ }, >+ "----------\n" + >+ "1. WARNING in p2\\B.java (at line 4)\n" + >+ " protected int field;\n" + >+ " ^^^^^\n" + >+ "The field B.field is hiding a field from type Interface\n" + >+ "----------\n"); >+} > public static Class testClass() { > return FieldAccessTest.class; > }
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 318171
:
172987
|
172990
| 172992