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

Summary: Introduce field performed on method parameter leads to 'Assignment to itself'
Product: java Reporter: Jachym_Vojtek
Component: RefactoringAssignee: Ralph Ruijs <ralphbenjamin>
Status: NEW ---    
Severity: normal    
Priority: P3    
Version: 8.0.2   
Hardware: PC   
OS: Windows 7   
Issue Type: DEFECT Exception Reporter:

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'.