Skip to content

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

Description

@abashev

What

Three small command-line problems, each also open in google-java-format:

  1. 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.
  2. 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.
  3. --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

  1. 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.
  2. 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.
  3. 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.

Activity

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