What
Three small command-line problems, each also open in google-java-format:
- Paths with spaces in an argfile: google/google-java-format#421.
CommandLineOptionsParser splits an @argfile at every whitespace character and knows no quotes, so the line "/tmp/dir with space/A.java" becomes three arguments. Each one is reported as "Skipping non-Java file", and the run exits 0 having formatted nothing. An argfile that names itself ends in a StackOverflowError.
- A thread pool that is never shut down: google/google-java-format#384.
Main.formatFiles creates a fixed thread pool on every call and never shuts it down. The command line does not notice, because the process exits, but a tool that calls Main in-process keeps up to MAX_THREADS idle threads per call.
--dry-run with --replace: google/google-java-format#1094. The error says "cannot use --dry-run and --in-place at the same time", but there is no --in-place; the flag is -i, -r or --replace.
Fix
- Port google/google-java-format#931 by Karlheinz Friedberger (open): a single- or double-quoted string in an argfile is one argument, and an argfile that includes itself is reported as an error.
- Close the pool when
formatFiles returns. On Java 21 ExecutorService is AutoCloseable and close() waits for the submitted tasks, so a try-with-resources is enough.
- Port google/google-java-format#1451 by rootkiller6788 (open): the message names
--replace.
Done when
CommandLineOptionsParserTest reads a quoted path with spaces from an argfile as one path, and a self-including argfile fails with a clear message;
- a
MainTest shows that no pool thread is left once format returns;
CommandLineFlagsTest expects --replace for both --replace --dry-run and -i -n;
- the ported commits keep their upstream authors.
What
Three small command-line problems, each also open in google-java-format:
CommandLineOptionsParsersplits an@argfileat every whitespace character and knows no quotes, so the line"/tmp/dir with space/A.java"becomes three arguments. Each one is reported as "Skipping non-Java file", and the run exits 0 having formatted nothing. An argfile that names itself ends in aStackOverflowError.Main.formatFilescreates a fixed thread pool on every call and never shuts it down. The command line does not notice, because the process exits, but a tool that callsMainin-process keeps up toMAX_THREADSidle threads per call.--dry-runwith--replace: google/google-java-format#1094. The error says "cannot use --dry-run and --in-place at the same time", but there is no--in-place; the flag is-i,-ror--replace.Fix
formatFilesreturns. On Java 21ExecutorServiceisAutoCloseableandclose()waits for the submitted tasks, so a try-with-resources is enough.--replace.Done when
CommandLineOptionsParserTestreads a quoted path with spaces from an argfile as one path, and a self-including argfile fails with a clear message;MainTestshows that no pool thread is left onceformatreturns;CommandLineFlagsTestexpects--replacefor both--replace --dry-runand-i -n;