Community
Participate
Working Groups
The built-in compiler does not flag assignment to this as an error. For example, the following class compiles and runs: package assign2this; public class Assign2This { Assign2This() { this = null; System.out.println("this: " + this); } public static void main(String[] args) { Assign2This t = new Assign2This(); System.out.println("ctor returned:" + t); } } Compiling with the Sun 1.4.2_02 javac returns an error: C:\orpe\jtst>c:\j2sdk1.4.2_02\bin\javac Assign2This.java Assign2This.java:3: cannot assign a value to final variable this this = null; ^ 1 error
In 3.0 recent build, an error is correctly reported against the assignment to this.
Reproduced in 2.1 stream.
Fixed in 2.1 stream (backported 3.0 code).
Added regression test: InitializationTest#test180.
Verified for 3.0M5
*** Bug 50688 has been marked as a duplicate of this bug. ***
Verified for 2.1.3 (M20040225)
*** Bug 58521 has been marked as a duplicate of this bug. ***
*** Bug 62205 has been marked as a duplicate of this bug. ***