{"record":{"id":"0f74b2d26ff59f93","repo":"stanfordnlp/CoreNLP","slug":"couldn-t-read-regexner-from-reader","errorCode":null,"errorMessage":"Couldn't read RegexNER from reader","messagePattern":"Couldn't read RegexNER from reader","errorType":"exception","errorClass":"edu.stanford.nlp.util.RuntimeIOException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/ie/regexp/RegexNERSequenceClassifier.java","lineNumber":157,"sourceCode":"   *                          text (e.g., to overwrite some older annotations).\n   * @param validPosRegex May be null or an empty String, in which case any (or no) POS is valid\n   *                      in matching. Otherwise, this is a regex, and only words with a POS that\n   *                      match the regex will be labeled via any matching rules.\n   */\n  public RegexNERSequenceClassifier(BufferedReader reader,\n                                    boolean ignoreCase,\n                                    boolean overwriteMyLabels,\n                                    String validPosRegex) {\n    super(new Properties());\n    if (validPosRegex != null && !validPosRegex.equals(\"\")) {\n      validPosPattern = Pattern.compile(validPosRegex);\n    } else {\n      validPosPattern = null;\n    }\n    try {\n      entries = readEntries(reader, ignoreCase);\n    } catch (IOException e) {\n      throw new RuntimeIOException(\"Couldn't read RegexNER from reader\", e);\n    }\n\n    this.ignoreCase = ignoreCase;\n    myLabels = Generics.newHashSet();\n    // Can always override background or none.\n    myLabels.add(flags.backgroundSymbol);\n    myLabels.add(null);\n    if (overwriteMyLabels) {\n      for (Entry entry: entries) myLabels.add(entry.type);\n    }\n    // log.info(\"RegexNER using labels: \" + myLabels);\n  }\n\n  /**\n   * Most AbstractSequenceClassifiers have classIndex set.\n   * ClassifierCombiner calls labels() to get the values from the\n   * index.\n   * <br>","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ie/regexp/RegexNERSequenceClassifier.java#L139-L175","documentation":"This Reader-based constructor of RegexNERSequenceClassifier reads entries from a caller-supplied BufferedReader; an IOException during readEntries is wrapped in RuntimeIOException with this message. Same failure family as the path-based constructor, but the source is the provided reader (closed/broken stream, network reader that failed).","triggerScenarios":"Constructing RegexNERSequenceClassifier with a Reader backed by a broken/closed stream or an IO failure mid-read of the mapping data (e.g. URL connection dropped, temp file deleted).","commonSituations":"Loading the mapping from a remote URL over a flaky connection, reusing an already-consumed/closed reader, or reading from a pipe that broke.","solutions":["Ensure the underlying stream is open and fully available before constructing the classifier.","Read the mapping into a String locally first (IOUtils.readerFromString) so failures are caught before construction.","Check the wrapped IOException cause (socket closed, file deleted) to fix the source.","Prefer the path/URL constructor for automatic retry-friendly loading."],"exampleFix":"// before\nnew RegexNERSequenceClassifier(props, new BufferedReader(new FileReader(mapping)), true, false);\n// after: load defensively first\nString text = IOUtils.slurpReader(reader);\nnew RegexNERSequenceClassifier(props, new BufferedReader(new StringReader(text)), true, false);","handlingStrategy":"try-catch","validationCode":"// Drain the reader into memory first so IO failures happen before construction\nString mappingText;\ntry {\n  mappingText = IOUtils.slurpReader(reader);\n} catch (IOException e) {\n  throw new IllegalStateException(\"Mapping source unavailable\", e);\n}","typeGuard":null,"tryCatchPattern":"try {\n  entriesReady = new RegexNERSequenceClassifier(props, new StringReader(mappingText), true, false);\n} catch (RuntimeIOException e) {\n  log.severe(\"Failed reading mapping from reader: \" + e.getCause());\n}","preventionTips":["Buffer the whole mapping in memory before constructing the classifier.","Never reuse an already-closed or partially consumed reader.","For remote mappings, download to a local file first."],"tags":["io","reader","regexner"],"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"}