stanfordnlp/CoreNLP · error · RuntimeIOException

edu.stanford.nlp.io.RuntimeIOException

Error message

edu.stanford.nlp.io.RuntimeIOException

What it means

RVFDataset.readSVMLightFormat (constructor/static reader) reads an SVM-light formatted file line by line; if a BufferedReader IOException occurs mid-read it wraps and rethrows it as edu.stanford.nlp.io.RuntimeIOException so callers of the constructor don't need checked exception handling. It indicates the input file could not be read completely (I/O failure, not a format problem).

Solutions

  1. Check the file is on a readable local filesystem and not being modified while reading
  2. Catch RuntimeIOException around the read call and inspect the cause (getCause() returns the original IOException) for the real problem
  3. Verify file permissions and that enough disk/memory are available
  4. Retry or re-copy the source file if the medium (network share, USB) is flaky

Example fix

// before
RVFDataset<String,String> ds = new RVFDataset<>("data.svmlight", -1);
// after
try {
  RVFDataset<String,String> ds = new RVFDataset<>("data.svmlight", -1);
} catch (RuntimeIOException e) {
  logger.severe("Failed reading data.svmlight: " + e.getCause());
  throw e;
}
Defensive patterns

Strategy: try-catch

Validate before calling

File f = new File(path);
if (!f.isFile()) throw new FileNotFoundException(path);
if (!f.canRead()) throw new IOException("No read permission: " + path);

Try / catch

try {
  RVFDataset<String,String> ds = new RVFDataset<>(path, -1);
} catch (RuntimeIOException e) {
  throw new RuntimeException("Could not read SVM-light file: " + path + " (cause: " + e.getCause() + ")", e);
}

Prevention

When it happens

Trigger: Calling the RVFDataset constructor / readSVMLightFormat with a filename whose file exists but whose stream fails during reading: disk error, file deleted mid-read, stream closed early, or permission/encoding issues at read time.

Common situations: Reading files from network mounts that drop connections; files truncated or locked by another process; running in containers with restricted filesystems where opening succeeds but reads fail.

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/766cbe8a06916aa7. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/classify/RVFDataset.java:765

      }
    }
  }

  private static RVFDataset<String, String> readSVMLightFormat(String filename, Index<String> featureIndex, Index<String> labelIndex, List<String> lines) {
    BufferedReader in = null;
    RVFDataset<String, String> dataset;
    try {
      dataset = new RVFDataset<>(10, featureIndex, labelIndex);
      in = IOUtils.readerFromString(filename);

      while (in.ready()) {
        String line = in.readLine();
        if (lines != null)
          lines.add(line);
        dataset.add(svmLightLineToRVFDatum(line));
      }
    } catch (IOException e) {
      throw new RuntimeIOException(e);
    } finally {
      IOUtils.closeIgnoringExceptions(in);
    }
    return dataset;
  }

  public static RVFDatum<String, String> svmLightLineToRVFDatum(String l) {
    l = l.replaceFirst("#.*$", ""); // remove any trailing comments
    String[] line = l.split("\\s+");
    ClassicCounter<String> features = new ClassicCounter<>();
    for (int i = 1; i < line.length; i++) {
      String[] f = line[i].split(":");
      if (f.length != 2) {
        throw new IllegalArgumentException("Bad data format: " + l);
      }
      double val = Double.parseDouble(f[1]);
      features.incrementCount(f[0], val);
    }

View on GitHub (pinned to 1b7edd19c4)