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 235878 - Introduce Parameter doesn't work when there a fieldname equals a parameter name
Summary: Introduce Parameter doesn't work when there a fieldname equals a parameter name
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Refactoring (show other bugs)
Version: 7.4
Hardware: PC Windows 7
: P3 normal with 1 vote (vote)
Assignee: Ralph Ruijs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-09-12 13:15 UTC by markiewb
Modified: 2014-02-02 02:17 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Shows the issue (32.16 KB, image/png)
2013-09-12 13:15 UTC, markiewb
Details

Note You need to log in before you can comment on or make changes to this bug.
Description markiewb 2013-09-12 13:15:27 UTC
Created attachment 139987 [details]
Shows the issue

* Take this code
package javaapplication5;

public class JavaApplication5
{
    private String foo;

    public void method(String foo)
    {
        System.out.println("foo = " + foo);
        
    }
}
* try to introduce parameter for the literal "foo = " -> dialog opens
* insert a new name ->

ACTUAL: Error "Name 'foo' is already used as a name of a field". I cannot proceed my refactoring. See screenshot

EXPECTED: Refactoring is possible

Product Version: NetBeans IDE Dev (Build 201309060001)
Java: 1.7.0_25; Java HotSpot(TM) 64-Bit Server VM 23.25-b01
Runtime: Java(TM) SE Runtime Environment 1.7.0_25-b17
System: Windows 7 version 6.1 running on amd64; Cp1252; de_DE (nb)
Comment 1 aldobrucale 2014-01-27 15:48:54 UTC
This used to work in netbeans 7.3
Comment 2 Ralph Ruijs 2014-01-30 13:03:13 UTC
The change was made by #235299. Introducing a parameter with the same name as a field will shadow it and can change the behavior.

Resolving as wontfix, but please let me know if this should be fixed differently.
Comment 3 aldobrucale 2014-01-30 14:01:59 UTC
I think that the fix for #235299 should only consider local variables declared in the scope where the parameter is being introduced: this would prevent the creation of uncompilable code. In all the other cases, it should be up to the user to decide if he wants or not to overshadow a variable.

The current fix for bug #235299 prevents the user from introducing parameters in constructors where the parameters shadows the class members, like this:

class A {
    final int a;

    public A(int a) {
        this.a = a;
    }
}

This is a pretty common idiom, so I think that allowing the introduction of new parameters in this scenario is more important than preventing the user from doing something that (except for the case of locally declared variables) he might as well want to do, and can easily be undone anyway.
Comment 4 Quality Engineering 2014-02-01 05:45:26 UTC
Integrated into 'main-silver', will be available in build *201402010001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/ca91feacc9c4
User: Ralph Benjamin Ruijs <ralphbenjamin@netbeans.org>
Log: #235878 - Introduce Parameter doesn't work when there a fieldname equals a parameter name
Comment 5 Ralph Ruijs 2014-02-01 15:34:44 UTC
Should be fixed by http://hg.netbeans.org/jet-main/rev/378e0c1fb64c
Comment 6 Quality Engineering 2014-02-02 02:17:23 UTC
Integrated into 'main-silver', will be available in build *201402020001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/378e0c1fb64c
User: Ralph Benjamin Ruijs <ralphbenjamin@netbeans.org>
Log: #235878 only show problem if variable is used.