This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 167376

Summary: [67cat] Quick Fix for "Local variable hides a field" picks wrong identifier to rename
Product: java Reporter: swpalmer <swpalmer>
Component: EditorAssignee: Max Sauer <msauer>
Status: VERIFIED FIXED    
Severity: blocker CC: sustaining
Priority: P3    
Version: 6.x   
Hardware: PC   
OS: Windows XP   
Issue Type: DEFECT Exception Reporter:

Description swpalmer 2009-06-19 16:02:04 UTC
[ BUILD # : 200906142201 ]
[ JDK VERSION : 1.6.* ]

I hit Alt-Enter on a line with a "Local variable hides a field"
warning and selected the only choice, "Rename the field" 

There are two problems

1 - I think this is wrong... the fix should be to "Rename the local
variable" (worst case - give both choices as a possibility)
2 - the editor jumps back in the code to an unrelated field in the
previous function and enters "rename mode"

e.g.
class A {
 private int value = 0;
 private String somethingElse = "whatever";

 public void hello() {
   somethingElse = "hello";
   System.out.println(somethingElse); // the editor tries to rename
"somethingElse"
 }

 public void doit() {
   int value = 42; // this is the line that has the warning and is
where I hit Alt-enter
   System.out.println(value);
 }
}

In the above example code that approximates the case in my project, I
will see the idea bulb for "value" in "doit()" and I hit alt-enter,
then select "rename field".  The editor then jumps into the previous
method "hello()" and begins a rename operation on "somethingElse".
Comment 1 swpalmer 2009-06-19 16:07:40 UTC
While I reproduced this *many* times in a row before filing the bug, as soon as I tried again after reporting the bug, it 
worked as expected.  So this may be difficult to reproduce - buit trust me it happened.  I was actually going through a 
file applying many quick-fixes (mostly adding Overrides annotations) and then when I came to this issue it failed in the 
manner described.

Note also that the fix that is applied renames the *local* variable, so the text for the fix "Rename the field" is still 
wrong.
Comment 2 Max Sauer 2009-06-22 12:33:36 UTC
I've corrected the label. In case the first issue occurs again, please reopen this one with a sample source. Thanks.
---
http://hg.netbeans.org/jet-main/rev/e0ae7009cf37
Comment 3 Quality Engineering 2009-06-23 07:44:21 UTC
Integrated into 'main-golden', will be available in build *200906230201* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/e0ae7009cf37
User: Max Sauer <msauer@netbeans.org>
Log: #167376: Field hidden by local variable label should reflect situation
Comment 4 Petr Blaha 2009-07-02 13:34:23 UTC
v.
Comment 5 pgebauer 2009-07-09 10:35:18 UTC
The fix has been ported into the release67_fixes repository.
http://hg.netbeans.org/release67_fixes/rev/a5b3457a1d7a
Comment 6 Jiri Prox 2009-07-16 17:09:17 UTC
v in 6.7.1

I cannot reproduce the renaming the wrong variable, it it occurs in 6.7.1 again, please file a new issue, thanks