Bug 130247 - [compiler] "Variable never used" is reported if variable is only referenced with this.variable
Summary: [compiler] "Variable never used" is reported if variable is only referenced w...
Status: RESOLVED INVALID
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.2 M6   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-03-02 18:37 EST by MG CLA
Modified: 2006-03-03 15:22 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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