palantir-java-format icon indicating copy to clipboard operation
palantir-java-format copied to clipboard

Error on long lambdas using method reference and long method names

Open fawind opened this issue 4 years ago • 0 comments

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));
    }
}

fawind avatar Mar 03 '21 17:03 fawind