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

Bug 130032

Summary: [inline] Method inlining does not detect/resolve shadowing of field
Product: [Eclipse Project] JDT Reporter: Brian Miller <bmiller>
Component: UIAssignee: Markus Keller <markus.kell.r>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: Brian.Miller, strider80
Version: 3.2   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard: stalebug

Description Brian Miller CLA 2006-03-01 16:27:58 EST
With 3.2M5, inlining foo() does it.

------------------ Bug.java ------------
class Bug {
    byte MAX_PRIORITY;
    
    void foo(){new Byte(MAX_PRIORITY);}
    
    {
        new Thread(){
            void bar(){foo();}
        };
    }
}
Comment 1 Markus Keller CLA 2006-06-09 05:32:09 EDT
Problem is that Thread.MAX_PRIORITY shadows Bug.MAX_PRIORITY. Could be resolved with
        new Thread(){
            void bar(){new Byte(Bug.this.MAX_PRIORITY);}
        };

rather than the current
        new Thread(){
            void bar(){new Byte(MAX_PRIORITY);}
        };
Comment 2 Brian Miller CLA 2008-07-31 13:21:39 EDT
Same problem with shadowed methods.  Eg, inlining method bar() declared on LINE 3 gives illegal result.

------------------------------ Bug.java ---------------------------
class Bug{
	void foo(){}
	void bar(){foo();} //LINE 3
	class Inner{
		{
			bar();
		}
		void foo()throws Exception{throw null;}
	}
}
Comment 3 Henno Vermeulen CLA 2015-05-21 06:31:07 EDT
This bug is still present. Searching for "inline" finds multiple duplicate bug reports for the issue with inner classes such as Bug 238120

I found an example that is even worse than the examples here because the resulting program still compiles but has different behavior. When running the following program it outputs

Old count = 0
New count = 5
Old count = 5
New count = 7

But after inlining the first call to getCount() it outputs:

Old count = 5
New count = 5
Old count = 7
New count = 7



public class Shadow {

	private int count;

	public void setCount(int count) {
		System.out.println("Old count = " + getCount());
		this.count = count;
		System.out.println("New count = " + getCount());
	}

	public int getCount() {
		return count;
	}

	public static void main(String[] args) {
		Shadow shadow = new Shadow();
		shadow.setCount(5);
		shadow.setCount(7);
	}

}
Comment 4 Eclipse Genie CLA 2018-09-12 00:03:42 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.