Bug 130247

Summary: [compiler] "Variable never used" is reported if variable is only referenced with this.variable
Product: [Eclipse Project] JDT Reporter: MG <java97301>
Component: CoreAssignee: Philipe Mulet <philippe_mulet>
Status: RESOLVED INVALID QA Contact:
Severity: normal    
Priority: P3    
Version: 3.2   
Target Milestone: 3.2 M6   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description MG CLA 2006-03-02 18:37:56 EST
The warning will be mistakenly output where the variable is being used but is references with this.variablename.
Comment 1 Philipe Mulet CLA 2006-03-03 04:20:04 EST
Can you please provide a testcase ?
Comment 2 Philipe Mulet CLA 2006-03-03 04:23:52 EST
Cannot reproduce. Following works fine:
public class X {
	private int value;
	void foo() {
		System.out.println(this.value);
		class L {
			int pos;
			void bar() {
				System.out.println(this.pos);
			}
		}
	}
}
Comment 3 MG CLA 2006-03-03 14:54:17 EST
Here you go...

public class ThisVariable {

    private boolean isDbUpdate;
   
    public void setIsDbUpdate(String isDbUpdate) {
        this.isDbUpdate = Boolean.valueOf(isDbUpdate).booleanValue();
    }
   
}
Comment 4 Philipe Mulet CLA 2006-03-03 15:15:07 EST
Thanks, reproduced.
Comment 5 Philipe Mulet CLA 2006-03-03 15:18:13 EST
Actually, this is intended behavior. 

The warning tells you the variable is never *read* from.
It is assigned, but the value is never consumed anywhere. It tells you that it is likely a useless field at the moment.

Boolean.valueOf(isDbUpdate)   only from reads the constructor argument, not from the field.
Comment 6 Philipe Mulet CLA 2006-03-03 15:22:15 EST
Added InitializationTest#test188