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 237311

Summary: [Introduce parameter] problem with vararg parameter
Product: java Reporter: ssazonov
Component: RefactoringAssignee: Ralph Ruijs <ralphbenjamin>
Status: RESOLVED WONTFIX    
Severity: normal CC: jiriprox
Priority: P4    
Version: 7.4   
Hardware: PC   
OS: Windows 7   
Issue Type: DEFECT Exception Reporter:
Attachments: before
after

Description ssazonov 2013-10-18 12:10:53 UTC
1. Create new simple java class:

package introduceParameter;

public class Class_A_A{

    public void m(int param, String... varargs ) {
        String x = "ABC";
        String y = "ABC";
        int z = 12345;
    }
    
    public void usage() {
        new Class_A_A();        
        m(1,"","");    
    }                                             
}

2. Select text "ABC" in statement String x = "ABC";

3. Bu Alt+Shift+P invoke introduce parameter dialog

4. Set this dialog according the attached image "before"

5. Press Refactor and you'll get broken code (see "after")

Product Version: NetBeans IDE 7.4 (Build 201310111528)
Java: 1.7.0_45; Java HotSpot(TM) 64-Bit Server VM 24.45-b08
Runtime: Java(TM) SE Runtime Environment 1.7.0_45-b18
System: Windows 7 version 6.1 running on amd64; Cp1252; en_US (nb)
Comment 1 ssazonov 2013-10-18 12:11:28 UTC
Created attachment 141249 [details]
before
Comment 2 ssazonov 2013-10-18 12:11:45 UTC
Created attachment 141250 [details]
after
Comment 3 Ralph Ruijs 2015-04-14 11:41:37 UTC
Reproducible, but not sure what the best fix would be. The other major IDEs do not solve it either
Comment 4 Jiri Prox 2015-04-16 10:21:40 UTC
I'm not sure about the best fix as well

One solution would be to to change all call m(1,"",""); to m(1, new String[]{"1", "2"}); but it will destroy the beauty of varargs.

Another solution would be not to perform refactoring is such case or at lest show warning. e.g. when introducing parameter of type T when there is vararg of type T...
Comment 5 Martin Balin 2016-07-07 07:17:53 UTC
This old bug may not be relevant anymore. If you can still reproduce it in 8.2 development builds please reopen this issue.

Thanks for your cooperation,
NetBeans IDE 8.2 Release Boss