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.
Summary: | Introduce Parameter doesn't work when there a fieldname equals a parameter name | ||
---|---|---|---|
Product: | java | Reporter: | markiewb |
Component: | Refactoring | Assignee: | Ralph Ruijs <ralphbenjamin> |
Status: | RESOLVED FIXED | ||
Severity: | normal | ||
Priority: | P3 | ||
Version: | 7.4 | ||
Hardware: | PC | ||
OS: | Windows 7 | ||
Issue Type: | DEFECT | Exception Reporter: | |
Attachments: | Shows the issue |
This used to work in netbeans 7.3 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. 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. 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 Should be fixed by http://hg.netbeans.org/jet-main/rev/378e0c1fb64c 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. |
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)