languagetool-org/languagetool · error · IllegalArgumentException

JSON output format makes no sense for profiling

Error message

JSON output format makes no sense for profiling

What it means

parseOptions rejects -p/--profile together with -l/--json. Profiling mode prints a human-readable per-rule timing table, which cannot be represented in JSON, so the parser throws IllegalArgumentException for the combination.

Source

Thrown at languagetool-commandline/src/main/java/org/languagetool/commandline/CommandLineParser.java:161

        }
        if (options.isBitext()) {
          throw new IllegalArgumentException("JSON output format is not implemented for Bitext");
        }
        if (options.isListUnknown()) {
          throw new IllegalArgumentException("You cannot list unknown words in JSON output format");
        }
      } else if (args[i].equals("-a") || args[i].equals("--apply")) {
        options.setApplySuggestions(true);
        if (options.isTaggerOnly()) {
          throw new IllegalArgumentException("You cannot apply suggestions when tagging only");
        }
        if (options.isJsonFormat()) {
          throw new IllegalArgumentException("JSON output format makes no sense for automatic application of suggestions");
        }
      } else if (args[i].equals("-p") || args[i].equals("--profile")) {
        options.setProfile(true);
        if (options.isJsonFormat()) {
          throw new IllegalArgumentException("JSON output format makes no sense for profiling");
        }
        if (options.isApplySuggestions()) {
          throw new IllegalArgumentException("Applying suggestions makes no sense for profiling");
        }
        if (options.isTaggerOnly()) {
          throw new IllegalArgumentException("Tagging makes no sense for profiling");
        }
      } else if (args[i].equals("--xmlfilter")) {
        options.setXmlFiltering(true);
      } else if (i == args.length - 1) {
        options.setFilename(args[i]);
      } else {
        throw new UnknownParameterException("Unknown parameter: " + args[i]);
      }
    }
    return options;
  }

View on GitHub (pinned to 2e990059ce)

Solutions

  1. Remove --json when profiling; parse the tab-separated profiling table instead
  2. Profile without --json and redirect stdout to a file for later processing
  3. Do not attempt to combine the two modes; the parser will always reject it

Example fix

// before
languagetool -l en -p --json file.txt
// after
languagetool -l en -p file.txt > profile.tsv
Defensive patterns

Strategy: validation

Validate before calling

if (hasFlag(args, "-p", "--profile") && hasFlag(args, "-l", "--json")) {
  throw new IllegalArgumentException("Profiling output is a text table, not JSON");
}

Type guard

static boolean hasFlag(String[] args, String... names) {
  for (String a : args) for (String n : names) if (a.equals(n)) return true;
  return false;
}

Try / catch

try {
  options = CommandLineParser.parseOptions(args);
} catch (IllegalArgumentException e) {
  System.err.println(e.getMessage());
  System.exit(2);
}

Prevention

When it happens

Trigger: Command line includes both --profile (or -p) and --json (or -l), e.g. `languagetool -p --json file.txt`; checked inside the profile branch via options.isJsonFormat().

Common situations: Trying to capture rule-performance measurements as JSON for automated analysis; combining a benchmarking flag with an output-format flag in CI scripts.

Understand the failure class

Background: "mutually exclusive" flag errors: what "can't supply both nx and xx", "--raw is not compatible with -i" and "cannot be used with" mean, and how to fix them — this error's family across 29 libraries.

Related errors


AI-assisted analysis of languagetool-org/languagetool@2e990059ce (2026-09-06). Data as JSON: /api/errors/50139027c37492b8. Report an issue: GitHub.