{"record":{"id":"a396808605b839db","repo":"stanfordnlp/CoreNLP","slug":"error-reading-threshold-file","errorCode":null,"errorMessage":"Error reading threshold file","messagePattern":"Error reading threshold file","errorType":"exception","errorClass":"edu.stanford.nlp.util.RuntimeIOException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/ie/ner/CMMClassifier.java","lineNumber":1309,"sourceCode":"\n\n  private static List<Pair<Pattern, Integer>> getThresholds(String filename) {\n    BufferedReader in = null;\n    try {\n      in = IOUtils.readerFromString(filename);\n      List<Pair<Pattern, Integer>> thresholds = new ArrayList<>();\n      for (String line; (line = in.readLine()) != null; ) {\n        int i = line.lastIndexOf(' ');\n        Pattern p = Pattern.compile(line.substring(0, i));\n        //log.info(\":\"+line.substring(0,i)+\":\");\n        Integer t = Integer.valueOf(line.substring(i + 1));\n        Pair<Pattern, Integer> pair = new Pair<>(p, t);\n        thresholds.add(pair);\n      }\n      in.close();\n      return thresholds;\n    } catch (IOException e) {\n      throw new RuntimeIOException(\"Error reading threshold file\", e);\n    } finally {\n      IOUtils.closeIgnoringExceptions(in);\n    }\n  }\n\n  public void trainSemiSup() {\n    DocumentReaderAndWriter<IN> readerAndWriter = makeReaderAndWriter();\n\n    String filename = flags.trainFile;\n    String biasedFilename = flags.biasedTrainFile;\n\n    ObjectBank<List<IN>> data =\n      makeObjectBankFromFile(filename, readerAndWriter);\n    ObjectBank<List<IN>> biasedData =\n      makeObjectBankFromFile(biasedFilename, readerAndWriter);\n\n    Index<String> featureIndex = new HashIndex<>();\n    Index<String> classIndex = new HashIndex<>();","sourceCodeStart":1291,"sourceCodeEnd":1327,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ie/ner/CMMClassifier.java#L1291-L1327","documentation":"When reading the thresholds file, any IOException is wrapped and rethrown as RuntimeIOException with message 'Error reading threshold file', preserving the cause. The threshold file path comes from the classifier's flags, so a bad path or unreadable file surfaces here.","triggerScenarios":"trainSemiSup / threshold-loading path where the thresholds file path (flags.thresholdsFile or equivalent) does not exist, is a directory, or cannot be read due to permissions; also truncated/corrupt files causing parse IOExceptions.","commonSituations":"Copying a serialized classifier without the thresholds file; relative path resolved against the wrong working directory; read-protected file in a cluster environment; misconfigured flag after a model move.","solutions":["Check the file exists and is readable (Files.isReadable) before training/semi-supervised runs","Correct the thresholds-file flag/property to the absolute path of the real file","Copy the thresholds file alongside the serialized model","Inspect the wrapped cause (e.getCause()) to distinguish missing file vs parse failure"],"exampleFix":"// before\nString path = \"thresholds.txt\"; // not present in CWD -> RuntimeIOException\n// after\nString path = \"/models/eng/thresholds.txt\";\nif (!new File(path).canRead()) throw new IllegalStateException(\"Thresholds file missing: \" + path);","handlingStrategy":"try-catch","validationCode":"File f = new File(thresholdsPath);\nif (!f.isFile() || !f.canRead()) throw new IllegalStateException(\"Thresholds file missing/unreadable: \" + f);","typeGuard":null,"tryCatchPattern":"try { thresholds = loadThresholds(); } catch (RuntimeIOException e) { throw new IllegalStateException(\"Fix thresholds file path: \" + thresholdsPath, e); }","preventionTips":["Ship the thresholds file together with the serialized model","Use absolute paths for the thresholds flag","Check the wrapped cause for the underlying IOException"],"tags":["java","io","file","ner"],"backgroundTag":"file-read-failed","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}