Skip to content

Report string-reflow failures cleanly instead of crashing the CLI #173

Closed as not planned

Description

@abashev

Upstream: google/google-java-format#1510
Kind: bug | Priority: medium

google-java-format#1510 (merged 2026-10-29, copybara export, fixing the crash from google-java-format#1439) covers the case where reflowing a long string literal yields code that no longer parses. javac's diagnostics then point at lines of the reflowed text, but the CLI printed them against the original input, and the diagnostic printer threw IndexOutOfBounds when the line was past the end of the input. The failure also left the worker thread pool running, so the process hung. Upstream now reports an unparsable reflow as an internal error, makes the diagnostic printer skip the source excerpt for out-of-range positions, and shuts the pool down in a finally block.

Why it matters: our StringWrapper.wrapOnce re-parses the reflowed result in the same way (it calls parse(result, ...) for the AST-equality check), so a bad reflow could surface javac diagnostics with output-relative line numbers. Our Main already uses try-with-resources for the executor (line ~127), so the hang part is probably not an issue; the diagnostic part needs checking.

Affected files in our repo:

  • open-java-format/src/main/java/com/palantir/javaformat/java/StringWrapper.java
  • open-java-format/src/main/java/com/palantir/javaformat/java/Main.java
  • the FormatterException diagnostic printing (locate its class; it is not in the java package directory)

Suggested action: investigate. Wrap the parse of the reflowed output so a failure becomes an "internal error, please report" FormatterException, and make the diagnostic printer tolerate out-of-range line numbers. Examples: not available - the item gives no input that triggers it.


Filed from an upstream-watch ticket after manual review.

Activity

  1. abashev commented on Oct 30, 2026

    @abashev
    CollaboratorAuthor

    Closing, because this does not reproduce here. I checked it on 21.X.X (6bcacfc).

    What is left is only theoretical. If a reflow ever produced code that does not parse, the file would fail with javac's message at a position in the reflowed text rather than in the input. Nothing broken would be written. I found no input that gets there; if one turns up, reopen this issue with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions