apache / netbeans

Apache NetBeans
https://netbeans.apache.org/
Apache License 2.0
2.55k stars 813 forks source link

"Fix All Imports" importing invalid static methods #7073

Open TFyre opened 2 months ago

TFyre commented 2 months ago

Apache NetBeans version

Apache NetBeans 20

What happened

Looks like "Fix All Imports" imports invalid static methods when the method name matches an existing import's root package.

image

Language / Project Type / NetBeans Component

Java Maven Application

How to reproduce

Create Maven Application and set source to 17 or 21 (works fine with 8):

pom.xml:

<maven.compiler.source>21</maven.compiler.source>

NewClass.java

package com.tfyre.test;

import java.util.List;
import javax.xml.parsers.DocumentBuilder;
import org.xml.sax.InputSource;

public class NewClass {

    private List<String> list;
    private DocumentBuilder foo;
    private InputSource is;

    public static class SomeClass2 {

        public static String java(String value) {
            return value;
        }

        public static String javax(String value) {
            return value;
        }

        public static String org(String value) {
            return value;
        }
    }

}
java -version
openjdk version "21.0.2" 2024-01-16 LTS
OpenJDK Runtime Environment Zulu21.32+17-CA (build 21.0.2+13-LTS)
OpenJDK 64-Bit Server VM Zulu21.32+17-CA (build 21.0.2+13-LTS, mixed mode, sharing)

Did this work correctly in an earlier version?

Apache NetBeans 19

Operating System

Windows

JDK

Zulu21.32+17-CA

Apache NetBeans packaging

Apache NetBeans binary zip

Anything else

Every time

Are you willing to submit a pull request?

Yes

TFyre commented 2 months ago

Possibly related to #6902?

TFyre commented 2 months ago

Duplicate of #5537?