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.
Consider 1. a package names pkg with: - a class named A - a class named B that contains a star import for anotherpkg.* 2. a package anotherpkg with a class named A The following cases do not depend on any possible personal settings regarding the imports formatting settings. If B uses pkg.A (referenced by simple name), an Organize Imports hints appears; the hint adds an unnecessary import for pkg.A. If B uses anotherpkg.A (again referenced by simple name, with an explicit import for it), an Organize Imports appears; the hint removes the (correct) import for anotherpkg.A, breaking the code.
Can you please attach sample code? I've tried to create it according to your description but it my case the organize import hint works fine. Probably the code was not same as yours. Please also attach build number and version. Thanks
NB 8.0 Build 201403101706 Maybe this bug (partly) depends on the formatting settings (Options > Editor > Formatting > Category: Imports), so I write them here for easier reproducibility: - Use Single Class Imports - Class Count To Use Star Import: 3 - Members Count To Use Static Star Import: 3 - Separate Static Imports All other radios/checkboxes are not selected. ### File pkg/Scanner.java ### package pkg; public class Scanner { public void doSomething() { } } ### File pkg/User.java (1st case) ### package pkg; import java.util.*; public class User { // The next 3 lines serve to keep the star import Date date; Formatter formatter; Random random; public void method(Scanner scanner) { scanner.doSomething(); } } ### File pkg/User.java (2nd case) ### package pkg; import java.util.*; import java.util.Scanner; public class User { // The next 3 lines serve to keep the star import Date date; Formatter formatter; Random random; public void method(Scanner scanner) { scanner.hasNext(); } } Renamings from the initial bug report: anotherpkg -> java.util, A -> Scanner, B -> User. In the 1st case, the simple name "Scanner" refers to pkg.Scanner and I receive an Organize Imports hint which adds a useless "import pkg.Scanner;". Of course, a Remove import from the same package hint appears afterwards. In the 2nd case, the simple name "Scanner" refers to java.util.Scanner (by virtue of the explicit import); if I apply the Organize Imports hint, such explicit import is removed and the code gets broken.
reproducible thanks for code sample
Fixed in jet-main#c958f8142610
Integrated into 'main-silver', will be available in build *201408100001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress) Changeset: http://hg.netbeans.org/main-silver/rev/c958f8142610 User: Svata Dedic <sdedic@netbeans.org> Log: #243667: fixed precedence of star/named/same-package imports