palantir / palantir/palantir-java-format
palantir-java-format crashes on several pieces of code in a codebase we were applying it to
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 907
- Forks
- 101
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 19
Description
What happened?
We applied palantir-java-format (using spotless in gradle) on a somewhat larger codebase, and it crashed on 3 different pieces of valid java code. We have worked around them by changing the code, but felt we should still report them.
public class Sample1 {
// Step 'palantir-java-format' found problem in 'samples/Sample1.java':
// 6:17: error: ')' expected
// com.palantir.javaformat.java.FormatterException: 6:17: error: ')' expected
public static final int PROBLEM_1 = (
1 // Comment
+ 2 // Comment
);
}
public class Sample2 {
// Step 'palantir-java-format' found problem in 'samples/Sample2.java':
// 12:18: error: did not generate token "A
// "
// com.palantir.javaformat.java.FormatterException: 12:18: error: did not generate token "A
// "
void problem_2(char c) {
switch (c) {
case '\u0000':
System.out.println("NUL");
case '\n': // \u000A
System.out.println("LF");
break;
}
}
}
// Step 'palantir-java-format' found problem in 'samples/Sample3.java':
// error: Imports not contiguous (perhaps a comment separates them?)
// com.palantir.javaformat.java.FormatterException: error: Imports not contiguous (perhaps a comment separates them?)
import java.math.BigInteger;
;
import java.math.BigDecimal;
Reproducing
I created a small project to create isolated recreations of the problematic pieces of code in gerritdrost/psychic-winner. There are 3 samples you can test using individual gradle tasks:
./gradlew spotlessSample1Check
./gradlew spotlessSample2Check
./gradlew spotlessSample3Check
What did you want to happen?
palantir-java-format not to crash on valid Java code. Especially samples 1 and 2 seem to be bugs. I'm not a 100% sure about sample 3.
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
Start by running spotlessSample1Check, spotlessSample2Check, and spotlessSample3Check from the linked reproduction project to confirm the three formatter failures. Read the Java formatter paths handling comments, Unicode character literals, and import separation. Done means valid Java code in all three samples is formatted or checked without a formatter crash.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100