{"record":{"id":"f7ecfd0a3a7d3b18","repo":"languagetool-org/languagetool","slug":"applying-suggestions-makes-no-sense-for-profiling","errorCode":null,"errorMessage":"Applying suggestions makes no sense for profiling","messagePattern":"Applying suggestions makes no sense for profiling","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"languagetool-commandline/src/main/java/org/languagetool/commandline/CommandLineParser.java","lineNumber":164,"sourceCode":"        }\n        if (options.isListUnknown()) {\n          throw new IllegalArgumentException(\"You cannot list unknown words in JSON output format\");\n        }\n      } else if (args[i].equals(\"-a\") || args[i].equals(\"--apply\")) {\n        options.setApplySuggestions(true);\n        if (options.isTaggerOnly()) {\n          throw new IllegalArgumentException(\"You cannot apply suggestions when tagging only\");\n        }\n        if (options.isJsonFormat()) {\n          throw new IllegalArgumentException(\"JSON output format makes no sense for automatic application of suggestions\");\n        }\n      } else if (args[i].equals(\"-p\") || args[i].equals(\"--profile\")) {\n        options.setProfile(true);\n        if (options.isJsonFormat()) {\n          throw new IllegalArgumentException(\"JSON output format makes no sense for profiling\");\n        }\n        if (options.isApplySuggestions()) {\n          throw new IllegalArgumentException(\"Applying suggestions makes no sense for profiling\");\n        }\n        if (options.isTaggerOnly()) {\n          throw new IllegalArgumentException(\"Tagging makes no sense for profiling\");\n        }\n      } else if (args[i].equals(\"--xmlfilter\")) {\n        options.setXmlFiltering(true);\n      } else if (i == args.length - 1) {\n        options.setFilename(args[i]);\n      } else {\n        throw new UnknownParameterException(\"Unknown parameter: \" + args[i]);\n      }\n    }\n    return options;\n  }\n\n  void printUsage() {\n    printUsage(System.out);\n  }","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/languagetool-org/languagetool/blob/2e990059ce67d5e2a0f7f7ca5d31160c6709df4b/languagetool-commandline/src/main/java/org/languagetool/commandline/CommandLineParser.java#L146-L182","documentation":"parseOptions rejects -p/--profile together with -a/--apply-suggestions. Profiling measures rule evaluation times on the input text; automatically rewriting the text with applied suggestions would change the workload and the output, so the combination throws IllegalArgumentException.","triggerScenarios":"Command line contains both --profile (or -p) and --apply-suggestions (or -a), e.g. `languagetool -p -a file.txt`; the check runs in the profile branch when options.isApplySuggestions() is true.","commonSituations":"Benchmarking a run while leaving an auto-correct flag enabled from a previous command; building a wrapper that always passes -a and occasionally adds -p for diagnostics.","solutions":["Remove -a/--apply-suggestions when profiling","Profile first to find slow rules, then run a separate -a pass to apply fixes","Keep profiling flags in a dedicated script that never sets -a"],"exampleFix":"// before\nlanguagetool -l en -p -a file.txt\n// after\nlanguagetool -l en -p file.txt   # profile\nlanguagetool -l en -a file.txt   # apply suggestions","handlingStrategy":"validation","validationCode":"if (hasFlag(args, \"-p\", \"--profile\") && hasFlag(args, \"-a\", \"--apply-suggestions\")) {\n  throw new IllegalArgumentException(\"--profile cannot be combined with --apply-suggestions\");\n}","typeGuard":"static boolean hasFlag(String[] args, String... names) {\n  for (String a : args) for (String n : names) if (a.equals(n)) return true;\n  return false;\n}","tryCatchPattern":"try {\n  options = CommandLineParser.parseOptions(args);\n} catch (IllegalArgumentException e) {\n  System.err.println(e.getMessage());\n  System.exit(2);\n}","preventionTips":["Profile measurement runs separately from text-rewriting runs","Use separate scripts for benchmarking and correction tasks","Review accumulated flags before adding -p"],"tags":["cli","commandline","profiling","mutually-exclusive-flags"],"backgroundTag":"mutually-exclusive-flags","analyzedSha":"2e990059ce67d5e2a0f7f7ca5d31160c6709df4b","analyzedAt":"2026-09-06T09:20:17.015Z","contentChangedAt":"2026-09-06T09:20:17.015Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}