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 159773 - If you static import two methods with the same name but different parameters, and use both methods, the first import is incorrectly designated as unused.
Summary: If you static import two methods with the same name but different parameters,...
Status: VERIFIED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 6.x
Hardware: PC Windows XP
: P3 blocker with 1 vote (vote)
Assignee: Max Sauer
URL:
Keywords:
: 155040 (view as bug list)
Depends on:
Blocks:
 
Reported: 2009-03-06 12:22 UTC by jonathanramsey
Modified: 2009-10-27 20:00 UTC (History)
1 user (show)

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 jonathanramsey 2009-03-06 12:22:58 UTC
In Test1.java, both the Arrays.sort and Collections.sort static methods are used in the main method. However, the
Arrays.sort static import is marked with the "Remove Unused Import" hint. This indicates that the static import for a
used method is being incorrectly identified as unused. If you do CTRL + SHIFT + I (to Fix Imports), the Arrays.sort
static import is removed, and you now get a compile error on the sort(new Object[0]); line.

=== Test1.java ===
import java.util.ArrayList;
import static java.util.Arrays.sort; // Import has "Remove Unused Import" hint.
import static java.util.Collections.sort;

public class Test1 {
    public static void main(String[] args) {
        sort(new Object[0]);
        sort(new ArrayList());
    }
}

Test2.java is a copy of Test1.java, except the two static imports are swapped around in order. Notice the "Remove Unused
Import" hint doesn't stay with the Arrays.sort import. Instead it displays next to the Collections.sort import. This
indicates that the first static import is being incorrectly identified as unused. If you do CTRL + SHIFT + I (to Fix
Imports), the Collections.sort static import is removed, and you now get a compile error on the sort(new ArrayList()); line.

=== Test2.java ===
import java.util.ArrayList;
import static java.util.Collections.sort; // Import has "Remove Unused Import" hint.
import static java.util.Arrays.sort;

public class Test2 {
    public static void main(String[] args) {
        sort(new Object[0]);
        sort(new ArrayList());
    }
}

Test3.java is a copy of Test1.java, except the use of Collections.sort has been replaced with Collections.shuffle.
Notice neither static import now has the "Remove Unused Import" hint. This indicates that the first static import is
only incorrectly identified as unused if both imports are for a method with the same name.

=== Test3.java ===
import java.util.ArrayList;
import static java.util.Arrays.sort;
import static java.util.Collections.shuffle;

public class Test3 {
    public static void main(String[] args) {
        sort(new Object[0]);
        shuffle(new ArrayList());
    }
}

This issue probably documents the same problem as the issue at http://www.netbeans.org/issues/show_bug.cgi?id=155040. 

However, the test case included on this issue has two differences from the test case on the other issue.
1. It uses two specific imports rather than one specific and one * import.
2. It has two public static methods rather than one public and one private static method.
Comment 1 Max Sauer 2009-03-06 12:44:23 UTC
Thanks for excellent bug report.
Comment 2 matthies 2009-03-27 00:26:09 UTC
*** Issue 155040 has been marked as a duplicate of this issue. ***
Comment 3 Max Sauer 2009-04-22 14:25:16 UTC
Fixed.
---
http://hg.netbeans.org/jet-main/rev/3b7749c26ee4
Comment 4 Quality Engineering 2009-04-23 08:59:35 UTC
Integrated into 'main-golden', will be available in build *200904230201* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/3b7749c26ee4
User: Max Sauer <msauer@netbeans.org>
Log: #159773: If you static import two methods with the same name but different parameters...
Comment 5 matthies 2009-10-27 20:00:43 UTC
Verified.