stanfordnlp/CoreNLP · error · edu.stanford.nlp.util.RuntimeIOException

Couldn't read RegexNER from reader

Error message

Couldn't read RegexNER from reader

What it means

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).

Solutions

  1. Ensure the underlying stream is open and fully available before constructing the classifier.
  2. Read the mapping into a String locally first (IOUtils.readerFromString) so failures are caught before construction.
  3. Check the wrapped IOException cause (socket closed, file deleted) to fix the source.
  4. Prefer the path/URL constructor for automatic retry-friendly loading.

Example fix

// before
new RegexNERSequenceClassifier(props, new BufferedReader(new FileReader(mapping)), true, false);
// after: load defensively first
String text = IOUtils.slurpReader(reader);
new RegexNERSequenceClassifier(props, new BufferedReader(new StringReader(text)), true, false);
Defensive patterns

Strategy: try-catch

Validate before calling

// Drain the reader into memory first so IO failures happen before construction
String mappingText;
try {
  mappingText = IOUtils.slurpReader(reader);
} catch (IOException e) {
  throw new IllegalStateException("Mapping source unavailable", e);
}

Try / catch

try {
  entriesReady = new RegexNERSequenceClassifier(props, new StringReader(mappingText), true, false);
} catch (RuntimeIOException e) {
  log.severe("Failed reading mapping from reader: " + e.getCause());
}

Prevention

When it happens

Trigger: 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).

Common situations: Loading the mapping from a remote URL over a flaky connection, reusing an already-consumed/closed reader, or reading from a pipe that broke.

Understand the failure class

Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.

Related errors


AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10). Data as JSON: /api/errors/0f74b2d26ff59f93. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/ie/regexp/RegexNERSequenceClassifier.java:157

   *                          text (e.g., to overwrite some older annotations).
   * @param validPosRegex May be null or an empty String, in which case any (or no) POS is valid
   *                      in matching. Otherwise, this is a regex, and only words with a POS that
   *                      match the regex will be labeled via any matching rules.
   */
  public RegexNERSequenceClassifier(BufferedReader reader,
                                    boolean ignoreCase,
                                    boolean overwriteMyLabels,
                                    String validPosRegex) {
    super(new Properties());
    if (validPosRegex != null && !validPosRegex.equals("")) {
      validPosPattern = Pattern.compile(validPosRegex);
    } else {
      validPosPattern = null;
    }
    try {
      entries = readEntries(reader, ignoreCase);
    } catch (IOException e) {
      throw new RuntimeIOException("Couldn't read RegexNER from reader", e);
    }

    this.ignoreCase = ignoreCase;
    myLabels = Generics.newHashSet();
    // Can always override background or none.
    myLabels.add(flags.backgroundSymbol);
    myLabels.add(null);
    if (overwriteMyLabels) {
      for (Entry entry: entries) myLabels.add(entry.type);
    }
    // log.info("RegexNER using labels: " + myLabels);
  }

  /**
   * Most AbstractSequenceClassifiers have classIndex set.
   * ClassifierCombiner calls labels() to get the values from the
   * index.
   * <br>

View on GitHub (pinned to 1b7edd19c4)