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 - [Introduce parameter] problem with vararg parameter
Summary: [Introduce parameter] problem with vararg parameter
Status: RESOLVED WONTFIX
Alias: None
Product: java
Classification: Unclassified
Component: Refactoring (show other bugs)
Version: 7.4
Hardware: PC Windows 7
: P4 normal (vote)
Assignee: Ralph Ruijs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-10-18 12:10 UTC by ssazonov
Modified: 2016-07-07 07:17 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
before (47.07 KB, image/png)
2013-10-18 12:11 UTC, ssazonov
Details
after (31.12 KB, image/png)
2013-10-18 12:11 UTC, ssazonov
Details

Note You need to log in before you can comment on or make changes to this bug.
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