palantir / palantir/palantir-java-format
Incorrectly removes java.lang import that disambiguates an import or same-package class
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 907
- Forks
- 101
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 19
Description
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)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the formatter behavior with the example/src/main/java/com/company/project/foo/Byte.java, bar/Byte.java, and bar/Test.java examples, starting with the import handling for java.lang.Byte. Done means formatting no longer removes the explicit import when it disambiguates a wildcard-imported or same-package class, avoiding the reported compilation failure.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100