Bug 46918 - assignment to this allowed by compiler
Summary: assignment to this allowed by compiler
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.1.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 2.1.3   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 50688 58521 62205 (view as bug list)
Depends on:
Blocks:
 
Reported: 2003-11-19 04:22 EST by Orjan Petersson CLA
Modified: 2004-05-14 06:59 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Orjan Petersson CLA 2003-11-19 04:22:56 EST
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
Comment 1 Philipe Mulet CLA 2003-11-19 07:56:55 EST
In 3.0 recent build, an error is correctly reported against the assignment to 
this.
Comment 2 Philipe Mulet CLA 2003-11-19 10:42:10 EST
Reproduced in 2.1 stream.
Comment 3 Philipe Mulet CLA 2003-11-19 12:02:07 EST
Fixed in 2.1 stream (backported 3.0 code).
Comment 4 Philipe Mulet CLA 2003-11-19 12:18:11 EST
Added regression test: InitializationTest#test180.
Comment 5 David Audel CLA 2003-11-24 10:25:53 EST
Verified for 3.0M5
Comment 6 Philipe Mulet CLA 2004-01-27 12:14:40 EST
*** Bug 50688 has been marked as a duplicate of this bug. ***
Comment 7 David Audel CLA 2004-03-01 12:04:05 EST
Verified for 2.1.3 (M20040225)
Comment 8 Philipe Mulet CLA 2004-04-15 07:33:22 EDT
*** Bug 58521 has been marked as a duplicate of this bug. ***
Comment 9 Philipe Mulet CLA 2004-05-14 06:59:56 EDT
*** Bug 62205 has been marked as a duplicate of this bug. ***