Skip to content

Incorrectly removes java.lang import that disambiguates an import or same-package class #1334

@JohnnyMorganz

Description

@JohnnyMorganz

Version: 2.68.0

Consider the following set up

// example/src/main/java/com/company/project/foo/Byte.java
package com.company.project.foo;

public class Byte {

}

// example/src/main/java/com/company/project/bar/Test.java
package com.company.project.bar;

import com.company.project.foo.*;

import java.lang.Byte;

public class Test {
    public Byte foo() {
        // ...
    }
}

Assume there are other relevant classes under src/main/java/com/company/project/foo.

When running palantir-java-format on Test.java, the java.lang.Byte is removed. However, this is incorrect, as it was used to disambiguate com.company.project.foo.Bar. This ends up leading to a compilation failure as we use the wrong Byte class.


Or more generally, if Byte was in the same package, and there was no other import:

// example/src/main/java/com/company/project/bar/Byte.java
package com.company.project.bar;

public class Byte {

}

// example/src/main/java/com/company/project/bar/Test.java
package com.company.project.bar;

import java.lang.Byte;

public class Test {
    public Byte foo() {
        // ...
    }
}

The java.lang.Byte import is still removed. This one is not as easy to workaround compared to the former (where we could've just expanded the wildcard imports)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions