You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Do not abort the whole file when a comment separates imports #245
google-java-format#1528 (merged, fixes google-java-format#424) changes ImportOrderer.findReplacements to return an empty replacement list instead of throwing when a block or Javadoc comment sits between two import declarations. The imports are left alone, but the rest of the file is still formatted. Today a compiling file with such a comment makes the whole run fail.
Our ImportOrderer still has the old behaviour: it throws "Imports not contiguous (perhaps a comment separates them?)" when another import follows the first import block. Any route that fixes imports (formatSourceAndFixImports, IDE plugins, the fixImports paths we track in open issues about import handling) fails on such files rather than formatting them.
Affected file: open-java-format/src/main/java/com/palantir/javaformat/java/ImportOrderer.java (the check after scanImports, around line 80).
Before (our formatter today: throws "Imports not contiguous", nothing is formatted):
Suggested action: port. It is a one-line change plus the upstream test (blockCommentBetweenImports) and an update of the existing ImportOrderer test that expects the exception. Decide whether to keep the stricter error behind an option; upstream simply dropped it.
Filed from an upstream-watch ticket after manual review.
The case described here no longer reproduces on 21.X.X: since #39 a comment between imports goes with the import after it, and the example above formats with the imports sorted (the Javadoc moves with java.util.List above java.util.Set), so the whole file is not aborted.
The "Imports not contiguous" check could still be reached by a stray ; between imports, a file the formatter rejects anyway. #248 ports the upstream change there, so the error reported is the parse error (extraneous semicolon) rather than the misleading message, and closes this issue.
Activity
abashev commentedon Nov 19, 2026
The case described here no longer reproduces on
21.X.X: since #39 a comment between imports goes with the import after it, and the example above formats with the imports sorted (the Javadoc moves withjava.util.Listabovejava.util.Set), so the whole file is not aborted.The "Imports not contiguous" check could still be reached by a stray
;between imports, a file the formatter rejects anyway. #248 ports the upstream change there, so the error reported is the parse error (extraneous semicolon) rather than the misleading message, and closes this issue.