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 242870 - Wrong hint "Remove unused import" ("Unused Import") while using wildcard and normal imports
Summary: Wrong hint "Remove unused import" ("Unused Import") while using wildcard and ...
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 8.0
Hardware: PC Windows 8
: P3 normal (vote)
Assignee: Svata Dedic
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-03-13 16:06 UTC by xehpuk
Modified: 2014-08-26 02:44 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 xehpuk 2014-03-13 16:06:55 UTC
Product Version = NetBeans IDE 8.0 RC1 (Build 201402242200)
Operating System = Windows 8 version 6.2 running on amd64
Java; VM; Vendor = 1.8.0
Runtime = Java HotSpot(TM) 64-Bit Server VM 25.0-b70

Consider these two classes both having a static method baz():

package foo;
public class Foo {
    public static void foo() {};
    public static void baz() {};
}

package bar;
public class Bar {
    public static void bar() {};
    public static void baz() {};
}

Then we have this class with wildcard imports calling the methods:

import static bar.Bar.*;
import static foo.Foo.*;
class Bug {
    void bug() {
        foo();
        bar();
        baz(); // "reference to baz is ambiguous"
    }
}

We get a correct compiler error for the ambiguous method call. We want to call Foo.baz(), so we add a normal import (btw. quick fixes would be nice):

import static bar.Bar.*;
import static foo.Foo.baz; // "Unused import"
import static foo.Foo.*;

The compiler error is gone, but now NetBeans claims that the new import is unused. Interestingly, it works when moving the normal import below the wildcard import:

import static bar.Bar.*;
import static foo.Foo.*;
import static foo.Foo.baz;

No errors, no warnings.
Comment 1 Jiri Prox 2014-03-13 16:14:26 UTC
reproducible
Comment 2 Svata Dedic 2014-08-22 09:22:41 UTC
Fixed in jet-main#242870
Comment 3 Quality Engineering 2014-08-26 02:44:29 UTC
Integrated into 'main-silver', will be available in build *201408260001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/9524e7a25f24
User: Svata Dedic <sdedic@netbeans.org>
Log: #242870: star imports take lower precedence than named ones.