Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 367534

Summary: [inline] Inline Local Variable does not qualify accesses to shadowed fields
Product: [Eclipse Project] JDT Reporter: Max Schaefer <max.schaefer>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: CLOSED DUPLICATE QA Contact:
Severity: normal    
Priority: P3 CC: daniel_megert, deepakazad, reprogrammer
Version: 3.8   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Whiteboard:

Description Max Schaefer CLA 2011-12-24 05:12:37 EST
Build Identifier: M20110909-1335

Consider the following program:

  public class A {
    int f = 42;
    int foo() {
      int r = f;
      int f = 23;
      return r;
    }
	
    public static void main(String[] args) {
      System.out.println(new A().foo());
    }
  }

This program prints "42". Note that the reference to field "f" in the initialiser of local variable "r" is shadowed later on by the local variable "f". Inlining local variable "r" yields the following program:


  public class A {
    int f = 42;
    int foo() {
      int f = 23;
      return f;  // should be "return this.f;"
    }
	
    public static void main(String[] args) {
      System.out.println(new A().foo());
    }
  }

This is wrong: the program now prints "23", since the reference "f" now refers to the local variable.

Reproducible: Always

Steps to Reproduce:
See above description.
Comment 1 Dani Megert CLA 2012-01-03 11:12:12 EST

*** This bug has been marked as a duplicate of bug 367536 ***