{"record":{"id":"be627cfdfbb184b6","repo":"languagetool-org/languagetool","slug":"profiling-mode-cannot-be-used-with-input-from-stdi","errorCode":null,"errorMessage":"Profiling mode cannot be used with input from STDIN","messagePattern":"Profiling mode cannot be used with input from STDIN","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"languagetool-commandline/src/main/java/org/languagetool/commandline/Main.java","lineNumber":213,"sourceCode":"        System.out.println(\"Unknown words: \" + lt.getUnknownWords());\n      }\n    }\n  }\n\n  private void runOnFileLineByLine(String filename, String encoding, JLanguageTool.Level level) throws IOException {\n    System.err.println(\"Warning: running in line by line mode. Cross-paragraph checks will not work.\\n\");\n    if (options.isVerbose()) {\n      lt.setOutput(System.err);\n    }\n    if (!options.isApplySuggestions()) {\n      if (isStdIn(filename)) {\n        System.err.println(\"Working on STDIN...\");\n      } else {\n        System.err.println(\"Working on \" + filename + \"...\");\n      }\n    }\n    if (profileRules && isStdIn(filename)) {\n      throw new IllegalArgumentException(\"Profiling mode cannot be used with input from STDIN\");\n    }\n    int runCount = 1;\n    List<Rule> rules = lt.getAllActiveRules();\n    if (profileRules) {\n      System.out.printf(\"Testing %d rules\\n\", rules.size());\n      System.out.println(\"Rule ID\\tTime\\tSentences\\tMatches\\tSentences per sec.\");\n      runCount = rules.size();\n    }\n    int lineOffset = 0;\n    int tmpLineOffset = 0;\n    handleLine(ApiPrintMode.START_API, 0, new StringBuilder(), level);\n    StringBuilder sb = new StringBuilder();\n    for (int ruleIndex = 0; !rules.isEmpty() && ruleIndex < runCount; ruleIndex++) {\n      currentRule = rules.get(ruleIndex);\n      try (\n          InputStreamReader isr = getInputStreamReader(filename, encoding);\n          BufferedReader br = new BufferedReader(isr)\n      ) {","sourceCodeStart":195,"sourceCodeEnd":231,"githubUrl":"https://github.com/languagetool-org/languagetool/blob/2e990059ce67d5e2a0f7f7ca5d31160c6709df4b/languagetool-commandline/src/main/java/org/languagetool/commandline/Main.java#L195-L231","documentation":"Main.runOnFileLineByLine processes input line by line and supports STDIN, but profiling mode (-p/--profile) needs to re-run the whole input repeatedly against all rules, which is impossible with a stream. When profileRules is true and isStdIn(filename) is true it throws IllegalArgumentException 'Profiling mode cannot be used with input from STDIN'.","triggerScenarios":"Running the tool in recursive/stdin-capable mode with profiling enabled and no filename (or '-' as filename), e.g. `cat file.txt | languagetool -p -l en` or omitting the filename while passing -p; runOnFileLineByLine is reached via runRecursive or main.","commonSituations":"Piping text into LanguageTool in a shell pipeline while leaving a profiling flag on; calling Main programmatically with \"\" or \"STDIN\" as filename together with profile=true.","solutions":["Pass a real file path on the command line when using -p/--profile","Remove the -p flag when input comes from STDIN","Write the piped content to a temp file first, then profile against that file"],"exampleFix":"# before\ncat document.txt | languagetool -l en -p\n# after\nlanguagetool -l en -p document.txt","handlingStrategy":"validation","validationCode":"boolean usesStdin = filename == null || filename.isEmpty() || \"STDIN\".equals(filename) || \"-\".equals(filename);\nif (profileRules && usesStdin) {\n  throw new IllegalArgumentException(\"Profiling requires a real file, not STDIN\");\n}","typeGuard":"static boolean isStdIn(String filename) {\n  return filename == null || filename.isEmpty() || \"STDIN\".equals(filename) || \"-\".equals(filename);\n}","tryCatchPattern":"try {\n  runMain(args);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().contains(\"STDIN\")) {\n    System.err.println(\"Provide a file path when using -p/--profile\");\n    System.exit(2);\n  }\n  throw e;\n}","preventionTips":["Always pass an explicit file path when profiling","Avoid piping into LanguageTool with -p enabled; buffer to a temp file instead","Validate inputs in wrapper scripts before invoking Main"],"tags":["cli","commandline","stdin","profiling"],"backgroundTag":"invalid-cli-argument","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"}