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 62485 Details for
Bug 151787
[compiler] compiler allows assignment to final field in constructor other than through 'this'
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Proposed patch
151787.txt (text/plain), 7.30 KB, created by
Philipe Mulet
on 2007-03-30 08:55:32 EDT
(
hide
)
Description:
Proposed patch
Filename:
MIME Type:
Creator:
Philipe Mulet
Created:
2007-03-30 08:55:32 EDT
Size:
7.30 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core.tests.compiler >Index: src/org/eclipse/jdt/core/tests/compiler/regression/AssignmentTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AssignmentTest.java,v >retrieving revision 1.38 >diff -u -r1.38 AssignmentTest.java >--- src/org/eclipse/jdt/core/tests/compiler/regression/AssignmentTest.java 15 Mar 2007 14:04:30 -0000 1.38 >+++ src/org/eclipse/jdt/core/tests/compiler/regression/AssignmentTest.java 30 Mar 2007 12:55:35 -0000 >@@ -150,6 +150,85 @@ > }, > "12"); > } >+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=151787 >+public void test004() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " private final Object o;\n" + >+ " X() {\n" + >+ " X other = this;\n" + >+ " other.o = new Object(); // illegal! other.o is not assignable\n" + >+ " } // error: this.o is not definitely assigned\n" + >+ " \n" + >+ " // incorrectly passes compilation\n" + >+ " static class Test5 {\n" + >+ " private final Object o;\n" + >+ "\n" + >+ " Test5() {\n" + >+ " Test5 other = this;\n" + >+ " other.o = new Object(); // illegal! other.o is not assignable\n" + >+ " } // error: this.o is not definitely assigned\n" + >+ " }\n" + >+ "\n" + >+ " // flags wrong statement as error\n" + >+ " static class Test6 {\n" + >+ " private final Object o;\n" + >+ " static Test6 initing;\n" + >+ "\n" + >+ " Test6() {\n" + >+ " initing = this;\n" + >+ " System.out.println(\"greetings\");\n" + >+ " Test6 other = initing;\n" + >+ " other.o = new Object(); // illegal! other.o is not assignable\n" + >+ " o = new Object(); // legal\n" + >+ " }\n" + >+ " }\n" + >+ "}\n", // ================= >+ }, >+ "----------\n" + >+ "1. WARNING in X.java (at line 2)\n" + >+ " private final Object o;\n" + >+ " ^\n" + >+ "The field X.o is never read locally\n" + >+ "----------\n" + >+ "2. ERROR in X.java (at line 3)\n" + >+ " X() {\n" + >+ " ^^^\n" + >+ "The blank final field o may not have been initialized\n" + >+ "----------\n" + >+ "3. ERROR in X.java (at line 5)\n" + >+ " other.o = new Object(); // illegal! other.o is not assignable\n" + >+ " ^\n" + >+ "The final field X.o cannot be assigned\n" + >+ "----------\n" + >+ "4. WARNING in X.java (at line 10)\n" + >+ " private final Object o;\n" + >+ " ^\n" + >+ "The field X.Test5.o is never read locally\n" + >+ "----------\n" + >+ "5. ERROR in X.java (at line 12)\n" + >+ " Test5() {\n" + >+ " ^^^^^^^\n" + >+ "The blank final field o may not have been initialized\n" + >+ "----------\n" + >+ "6. ERROR in X.java (at line 14)\n" + >+ " other.o = new Object(); // illegal! other.o is not assignable\n" + >+ " ^\n" + >+ "The final field X.Test5.o cannot be assigned\n" + >+ "----------\n" + >+ "7. WARNING in X.java (at line 20)\n" + >+ " private final Object o;\n" + >+ " ^\n" + >+ "The field X.Test6.o is never read locally\n" + >+ "----------\n" + >+ "8. ERROR in X.java (at line 27)\n" + >+ " other.o = new Object(); // illegal! other.o is not assignable\n" + >+ " ^\n" + >+ "The final field X.Test6.o cannot be assigned\n" + >+ "----------\n"); >+} > // final multiple assignment > public void test020() { > this.runNegativeTest( >#P org.eclipse.jdt.core >Index: compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedNameReference.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedNameReference.java,v >retrieving revision 1.115 >diff -u -r1.115 QualifiedNameReference.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedNameReference.java 15 Mar 2007 15:49:43 -0000 1.115 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedNameReference.java 30 Mar 2007 12:55:36 -0000 >@@ -42,12 +42,7 @@ > this.sourceEnd = sourceEnd; > } > >- public FlowInfo analyseAssignment( >- BlockScope currentScope, >- FlowContext flowContext, >- FlowInfo flowInfo, >- Assignment assignment, >- boolean isCompound) { >+ public FlowInfo analyseAssignment(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo, Assignment assignment, boolean isCompound) { > > // determine the rank until which we now we do not need any actual value for the field access > int otherBindingsCount = otherBindings == null ? 0 : otherBindings.length; >@@ -74,11 +69,11 @@ > currentScope.problemReporter().enumStaticFieldUsedDuringInitialization(lastFieldBinding, this); > } > } >- } >+ } > // check if final blank field > if (lastFieldBinding.isBlankFinal() >- && this.otherBindings != null // the last field binding is only assigned >- && currentScope.allowBlankFinalFieldAssignment(lastFieldBinding)) { >+ && this.otherBindings != null // the last field binding is only assigned >+ && currentScope.allowBlankFinalFieldAssignment(lastFieldBinding)) { > if (!flowInfo.isDefinitelyAssigned(lastFieldBinding)) { > currentScope.problemReporter().uninitializedBlankFinalField( > lastFieldBinding, >@@ -126,12 +121,10 @@ > > if (isCompound) { > if (otherBindingsCount == 0 >- && lastFieldBinding.isBlankFinal() >- && currentScope.allowBlankFinalFieldAssignment(lastFieldBinding) >- && (!flowInfo.isDefinitelyAssigned(lastFieldBinding))) { >- currentScope.problemReporter().uninitializedBlankFinalField( >- lastFieldBinding, >- this); >+ && lastFieldBinding.isBlankFinal() >+ && currentScope.allowBlankFinalFieldAssignment(lastFieldBinding) >+ && (!flowInfo.isDefinitelyAssigned(lastFieldBinding))) { >+ currentScope.problemReporter().uninitializedBlankFinalField(lastFieldBinding, this); > } > TypeBinding lastReceiverType; > switch (otherBindingsCount) { >@@ -164,10 +157,10 @@ > // the last field access is a write access > if (lastFieldBinding.isFinal()) { > // in a context where it can be assigned? >- if (lastFieldBinding.isBlankFinal() >+ if (otherBindingsCount == 0 >+ && lastFieldBinding.isBlankFinal() > && !isCompound >- && currentScope.allowBlankFinalFieldAssignment(lastFieldBinding) >- && indexOfFirstFieldBinding == 1) { >+ && currentScope.allowBlankFinalFieldAssignment(lastFieldBinding)) { > if (flowInfo.isPotentiallyAssigned(lastFieldBinding)) { > currentScope.problemReporter().duplicateInitializationOfBlankFinalField(lastFieldBinding, this); > } else { >@@ -176,7 +169,7 @@ > flowInfo.markAsDefinitelyAssigned(lastFieldBinding); > } else { > currentScope.problemReporter().cannotAssignToFinalField(lastFieldBinding, this); >- if (currentScope.allowBlankFinalFieldAssignment(lastFieldBinding)) { // pretend it got assigned >+ if (otherBindingsCount == 0 && currentScope.allowBlankFinalFieldAssignment(lastFieldBinding)) { // pretend it got assigned > flowInfo.markAsDefinitelyAssigned(lastFieldBinding); > } > }
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 151787
:
46788
|
62485
|
62503
|
62551