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 256667 - Introduce field performed on method parameter leads to 'Assignment to itself'
Summary: Introduce field performed on method parameter leads to 'Assignment to itself'
Status: NEW
Alias: None
Product: java
Classification: Unclassified
Component: Refactoring (show other bugs)
Version: 8.0.2
Hardware: PC Windows 7
: P3 normal (vote)
Assignee: Ralph Ruijs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-11-18 16:00 UTC by Jachym_Vojtek
Modified: 2015-11-18 16:00 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jachym_Vojtek 2015-11-18 16:00:57 UTC
class Test {
    void foo(String something) {
        System.out.println(something); // Select 'something'->Refactor->Introduce->Field..., use default on the dialog
    }
    private String something;
}


will be transformed to 

class Test {
    void foo(String something) {        
        something = something;
        System.out.println(something); // Select 'something'->Refactor->Introduce->Field..., use default on the dialog
    }
    private String something;
}

The resulting code does not make much sense as it leads to 'Assignment to itself'.
I would say that:
1) User should not be offered (by default) the name of field which is shadowed in the method by the method parameter.
2) If this shadowing occurs, the usage of the field in the method should be qualified by 'this'.