Skip to content

Command line: quoted argfile paths, a closed thread pool, and the right flag in the --dry-run error - #45

Closed
abashev wants to merge 3 commits into
mainfrom
cli-argfile-pool-dry-run
Closed

abashev wants to merge 3 commits into
mainfrom
cli-argfile-pool-dry-run

Conversation

@abashev

@abashev abashev commented Sep 23, 2026

Copy link
Copy Markdown
Collaborator

Closes #40. Upstream reports: google/google-java-format#421, google/google-java-format#384, google/google-java-format#1094.

Three command-line fixes, one commit each. Two are ported from open upstream PRs and keep their authors.

From upstream, with the authors kept

Added here

  • The thread pool is closed when Main.formatFiles returns. The command line did not notice the leak, because it exits, but a tool that runs Main in-process kept up to MAX_THREADS idle threads per call. On Java 21 ExecutorService is AutoCloseable, and close() waits for the submitted tasks, which have all been waited for by then.

Checked

  • Test first for each part:
    • the quoting and recursion cases from Incompatible with JDK 21 palantir/palantir-java-format#931 fail without the parser change (the nesting case passes either way and guards what already worked);
    • MainTest.formatLeavesNoPoolThreadRunning fails with "pool-1-thread-1 is still running";
    • CommandLineFlagsTest.inPlaceDryRun fails on the old message.
  • ./gradlew :open-java-format:test on JDK 21: 1421 tests, all green.
  • The jar formats the 15,747 files of the JDK 21 sources from one argfile, byte for byte as before.
  • By hand: a quoted path with spaces in an argfile formats that file, a self-including argfile prints the new error, and --dry-run --replace names --replace.

kfriedberger and others added 3 commits September 23, 2026 10:43
…cludes itself

CommandLineOptionsParser split an @argfile at every whitespace character
and knew no quotes, so a path with a space in it became several
arguments. Each was reported as "Skipping non-Java file", and the run
still exited 0 (#40, from google/google-java-format#421). A parameter
file that included itself recursed until the stack overflowed.

This ports google/google-java-format#931 by Karlheinz Friedberger, its
three commits squashed into one. An argument in a parameter file may be
quoted with double or single quotes and then keeps its whitespace; an
unclosed quote runs to the end of the file; and a file that is already
being read is reported as "parameter file was included recursively".
Escaped quotes are not handled, as upstream. The three
CommandLineOptionsParserTest cases come from that PR.
Main.formatFiles created a fixed thread pool on every call and never
shut it down. The command line does not notice, because the process
exits, but a tool that runs Main in-process kept up to MAX_THREADS idle
threads per call (#40, from google/google-java-format#384).

The pool is now closed when formatFiles returns. On Java 21
ExecutorService is AutoCloseable, and close() waits for the submitted
tasks, which formatFiles has already waited for by then. The new
MainTest runs format from a thread of its own thread group, which the
pool's threads join, and fails without the change because a pool
thread is still running.
"cannot use --dry-run and --in-place at the same time" named a flag
that does not exist: in-place formatting is -i, -r, -replace or
--replace (#40, from google/google-java-format#1094). The message now
says --replace, the long form the usage text shows.

This ports google/google-java-format#1451 by rootkiller6788, including
its test for the --replace --dry-run spelling next to -i -n.
@abashev

abashev commented Sep 23, 2026

Copy link
Copy Markdown
Collaborator Author

Split into one PR per fix, for review: the thread pool is #47 and the --dry-run message is #48. The argfile quoting commit is already on main as f5e6b12.

@abashev abashev closed this Sep 23, 2026
auto-merge was automatically disabled September 23, 2026 08:46

Pull request was closed

@abashev

abashev commented Sep 23, 2026

Copy link
Copy Markdown
Collaborator Author

Correction: main was reset, and the argfile quoting change is now #49.

@abashev
abashev deleted the cli-argfile-pool-dry-run branch September 23, 2026 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Command line: argfile paths with spaces, a thread pool never shut down, a --dry-run error naming a missing flag

3 participants