diff --git a/changelog/@unreleased/pr-85.v2.yml b/changelog/@unreleased/pr-85.v2.yml new file mode 100644 index 000000000..751833647 --- /dev/null +++ b/changelog/@unreleased/pr-85.v2.yml @@ -0,0 +1,6 @@ +type: fix +fix: + description: "When inlining a level's leading docs, check that no breaks were introduced + more robustly." + links: + - https://github.com/palantir/palantir-java-format/pull/85 diff --git a/palantir-java-format/src/main/java/com/palantir/javaformat/doc/Level.java b/palantir-java-format/src/main/java/com/palantir/javaformat/doc/Level.java index 1a21c0b33..a513f2821 100644 --- a/palantir-java-format/src/main/java/com/palantir/javaformat/doc/Level.java +++ b/palantir-java-format/src/main/java/com/palantir/javaformat/doc/Level.java @@ -295,8 +295,11 @@ private Optional tryBreakLastLevel( SplitsBreaks prefixSplitsBreaks = splitByBreaks(leadingDocs); State state1 = tryToLayOutLevelOnOneLine(commentsHelper, maxWidth, state, prefixSplitsBreaks, explorationNode); - Preconditions.checkState( - !state1.mustBreak(), "We messed up, it wants to break a bunch of splits that shouldn't be broken"); + // If a break was still forced somehow even though we could fit the leadingWidth, then abort. + // This could happen if inner levels have set a `columnLimitBeforeLastBreak` or something like that. + if (state1.numLines() != state.numLines()) { + return Optional.empty(); + } // Ok now how to handle the last level? // There are two options: diff --git a/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/palantir-conjure-java-runtime-1285-1.output b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/palantir-conjure-java-runtime-1285-1.output index a011da382..0c6194789 100644 --- a/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/palantir-conjure-java-runtime-1285-1.output +++ b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/palantir-conjure-java-runtime-1285-1.output @@ -8,8 +8,10 @@ class PalantirConjureJavaRuntime1285_SslSocketFactories { KeyManager[] keyManagers = null; if (config.keyStorePath().isPresent()) { keyManagers = createKeyManagerFactory( - config.keyStorePath().get(), config.keyStorePassword() - .get(), config.keyStoreType(), config.keyStoreKeyAlias()) + config.keyStorePath().get(), + config.keyStorePassword().get(), + config.keyStoreType(), + config.keyStoreKeyAlias()) .getKeyManagers(); }