{"record":{"id":"4ec533531fbdfdee","repo":"languagetool-org/languagetool","slug":"file-not-found-inputfile","errorCode":null,"errorMessage":"File not found: ${inputFile}","messagePattern":"File not found: (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"languagetool-http-client/src/main/java/org/languagetool/remote/SentenceAnnotator.java","lineNumber":669,"sourceCode":"\n    void prepareConfiguration() throws IOException {\n      CheckConfigurationBuilder cfgBuilder = new CheckConfigurationBuilder(languageCode);\n      // cfgBuilder.textSessionID(\"-2\");\n      if (enabledOnlyRules.isEmpty()) {\n        cfgBuilder.disabledRuleIds(\"WHITESPACE_RULE\");\n        if (!disabledRules.isEmpty()) {\n          cfgBuilder.disabledRuleIds(disabledRules);\n        }\n      } else {\n        cfgBuilder.enabledRuleIds(enabledOnlyRules).enabledOnly();\n      }\n      if (!userName.isEmpty() && !apiKey.isEmpty()) {\n        cfgBuilder.username(userName).apiKey(apiKey).build();\n      }\n      ltConfig = cfgBuilder.build();\n      inputFile = new File(inputFilePath);\n      if (!inputFile.exists() || inputFile.isDirectory()) {\n        throw new IOException(\"File not found: \" + inputFile);\n      }\n      String fileName = inputFile.getName();\n      // System.out.println(\"Analyzing file: \" + fileName);\n      fileName = fileName.substring(0, fileName.lastIndexOf('.'));\n      if (outputFilePath.isEmpty()) {\n        outputFile = new File(inputFile.getParentFile() + \"/\" + fileName + \"-annotations.csv\");\n      } else {\n        outputFile = new File(outputFilePath);\n      }\n      outStrB = new StringBuilder();\n      out = new FileWriter(outputFile, true);\n      cachedMatches = new HashMap<>();\n      lt = new RemoteLanguageTool(Tools.getUrl(remoteServer));\n    }\n\n  }\n\n  private static String printTimeFromStart(long start, String tag) {","sourceCodeStart":651,"sourceCodeEnd":687,"githubUrl":"https://github.com/languagetool-org/languagetool/blob/2e990059ce67d5e2a0f7f7ca5d31160c6709df4b/languagetool-http-client/src/main/java/org/languagetool/remote/SentenceAnnotator.java#L651-L687","documentation":"The SentenceAnnotator constructor converts the given inputFilePath into a File and throws an IOException when the path does not exist or is a directory. It needs a readable, existing data file to annotate; directories and missing paths cannot be processed.","triggerScenarios":"Constructing SentenceAnnotator with a path that was never created, a typo'd filename, a directory path instead of a file, or a file deleted between argument parsing and construction.","commonSituations":"Relative path resolved from a different working directory; path containing spaces unquoted in the shell; expecting the tool to accept a directory of files.","solutions":["Verify the path with ls (or Files.exists) and pass the exact existing file path","Pass an absolute path or run from the directory containing the input file","Ensure the target is a regular file, not a directory","Check the file exists before constructing: new File(path).isFile()"],"exampleFix":"// before\nSentenceAnnotator ann = new SentenceAnnotator(\"./input/annot.txt\", out, ...); // file missing\n// after\nFile f = new File(\"./input/annot.txt\");\nif (!f.isFile()) throw new IllegalArgumentException(\"input file missing: \" + f);\nSentenceAnnotator ann = new SentenceAnnotator(f.getPath(), out, ...);","handlingStrategy":"validation","validationCode":"Path p = Paths.get(inputFilePath);\nif (!Files.isRegularFile(p)) {\n  throw new IllegalArgumentException(\"input must be an existing file: \" + p.toAbsolutePath());\n}","typeGuard":"static boolean isReadableFile(String path) {\n  File f = new File(path);\n  return f.isFile() && f.exists() && f.canRead();\n}","tryCatchPattern":"try {\n  SentenceAnnotator a = new SentenceAnnotator(inputFilePath, out, username, apiKey, ltUrl, ...);\n} catch (IOException e) {\n  if (e.getMessage().startsWith(\"File not found\")) {\n    System.err.println(\"check path (must be a file, absolute if unsure): \" + e.getMessage());\n  } else throw e;\n}","preventionTips":["Use absolute paths or verify the working directory before invoking","Quote paths with spaces in the shell","Pass a file, never a directory, as inputFilePath"],"tags":["java","file-not-found","io"],"backgroundTag":"file-not-found","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"}