palantir / palantir/palantir-java-format

Error on long lambdas using method reference and long method names

Open
#429 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Java
Stars
907
Forks
101
Avg merge
1d 3h
Merged PRs (30d)
19

Description

Failing test case: https://github.com/palantir/palantir-java-format/commit/ee11eb7da8ca609db55c469da3377e1f1cc2d2c7

Example:

public class MyClass {
    Object myMethod() {
        return new MyVeryLongClassNamexxxxxxxxxxxxxxxxxxxxxxxxxxxxx(
                longishMethodA()::longishMethodBxxxxxxxxxxxxxxxxxxxxx);
    }
}

Stacktrace:

java.lang.IllegalStateException: Didn't find expected break at the beginning of level.


	at com.palantir.javaformat.doc.CountWidthUntilBreakVisitor.visitLevel(CountWidthUntilBreakVisitor.java:73)
	at com.palantir.javaformat.doc.CountWidthUntilBreakVisitor.visitLevel(CountWidthUntilBreakVisitor.java:25)
	at com.palantir.javaformat.doc.DocVisitor.visit(DocVisitor.java:22)
	at com.palantir.javaformat.doc.Level.tryBreakInnerLevel_acceptInlineChain(Level.java:450)
	at com.palantir.javaformat.doc.Level.tryBreakInnerLevel(Level.java:416)
	at com.palantir.javaformat.doc.Level.tryInlineSuffix(Level.java:367)
	at com.palantir.javaformat.doc.Level.lambda$tryBreakInnerLevel_checkInner$16(Level.java:494)
	at com.palantir.javaformat.doc.Obs$LevelNodeImpl.maybeExplore(Obs.java:136)
	at com.palantir.javaformat.doc.Level.lambda$tryBreakInnerLevel_checkInner$17(Level.java:491)
	at com.palantir.javaformat.BreakBehaviours$LambdaCases.inlineSuffix(BreakBehaviours.java:113)
	at com.palantir.javaformat.BreakBehaviours$InlineSuffix.match(BreakBehaviours.java:161)
	at com.palantir.javaformat.BreakBehaviours$CaseOfMatchers$PartialMatcher.otherwise(BreakBehaviours.java:558)
	at com.palantir.javaformat.BreakBehaviours$CaseOfMatchers$PartialMatcher.otherwise_(BreakBehaviours.java:562)
	at com.palantir.javaformat.doc.Level.tryBreakInnerLevel_checkInner(Level.java:551)
	at com.palantir.javaformat.doc.Level.tryBreakInnerLevel(Level.java:422)
	at com.palantir.javaformat.doc.Level.tryBreakLastLevel(Level.java:345)
	at com.palantir.javaformat.doc.Level.lambda$tryBreakInnerLevel_checkInner$14(Level.java:485)
	at com.palantir.javaformat.doc.Obs$LevelNodeImpl.maybeExplore(Obs.java:136)
	at com.palantir.javaformat.doc.Level.lambda$tryBreakInnerLevel_checkInner$15(Level.java:482)
	at com.palantir.javaformat.BreakBehaviours$LambdaCases.preferBreakingLastInnerLevel(BreakBehaviours.java:108)
	at com.palantir.javaformat.BreakBehaviours$PreferBreakingLastInnerLevel.match(BreakBehaviours.java:146)
	at com.palantir.javaformat.BreakBehaviours$CaseOfMatchers$PartialMatcher.otherwise(BreakBehaviours.java:558)
	at com.palantir.javaformat.BreakBehaviours$CaseOfMatchers$PartialMatcher.otherwise_(BreakBehaviours.java:562)
        [....]

Projects should be able to workaround by doing something like:

public class MyClass {
    Object myMethod() {
        return new MyVeryLongClassNamexxxxxxxxxxxxxxxxxxxxxxxxxxxxx(
                x -> longishMethodA().longishMethodBxxxxxxxxxxxxxxxxxxxxx(x));
    }
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the failing example from commit ee11eb7da8ca609db55c469da3377e1f1cc2d2c7 and inspect CountWidthUntilBreakVisitor.visitLevel, where the stack trace reports the failure. Trace the related Level break-handling calls and verify the formatter processes the long method-reference example without throwing IllegalStateException while producing valid formatted Java.

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
Clearly specified
Newbie friendliness
65/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.