stanfordnlp/CoreNLP · critical · RuntimeException
Could not open temporary feature index file for writing.
Error message
Could not open temporary feature index file for writing.
What it means
With flags.saveFeatureIndexToDisk enabled, training writes the feature index to a temp file per fold via IOUtils.writeObjectToTempFile. If that write throws IOException (unwritable temp dir, no disk space, security restrictions), it is wrapped in this RuntimeException because training cannot proceed without persisting the index.
Solutions
- Check disk space and make java.io.tmpdir writable, or set -Djava.io.tmpdir to a writable directory.
- Disable saveFeatureIndexToDisk so the feature index stays in memory if it fits.
- Inspect the wrapped IOException (root cause) for the precise IO failure and fix it.
Example fix
// before java -Djava.io.tmpdir=/nonexistent -cp ... edu.stanford.nlp.ie.crf.CRFClassifier ... // after java -Djava.io.tmpdir=/data/tmp -cp ... edu.stanford.nlp.ie.crf.CRFClassifier ... // or remove saveFeatureIndexToDisk=true from the properties
Defensive patterns
Strategy: try-catch
Validate before calling
File tmpDir = new File(System.getProperty("java.io.tmpdir"));
if (!tmpDir.canWrite() || tmpDir.getUsableSpace() < 100L * 1024 * 1024) {
throw new IllegalStateException("tmpdir not writable or low on space: " + tmpDir);
}
// or simply don't set saveFeatureIndexToDisk=true when the index fits in memory Try / catch
try {
classifier.train(files);
} catch (RuntimeException e) {
if (String.valueOf(e.getMessage()).contains("temporary feature index file for writing")) {
props.remove("saveFeatureIndexToDisk"); // keep index in memory
// rebuild classifier and retry, or fix tmpdir first
} else throw e;
} Prevention
- Ensure java.io.tmpdir is writable with ample free space before long training.
- Enable saveFeatureIndexToDisk only when the feature index genuinely exceeds memory.
- Monitor disk space during training runs.
When it happens
Trigger: flags.saveFeatureIndexToDisk=true and IOUtils.writeObjectToTempFile throws IOException — e.g. java.io.tmpdir not writable, disk full, or a security manager blocking temp file creation.
Common situations: Read-only or full /tmp on shared servers and containers; restrictive tmpdir; sandboxed CI environments with no temp write access.
Understand the failure class
Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.
Related errors
- Could not open temporary feature index file for reading.
- Could not create directory <tgtDir.getAbsolutePath()>, as a…
- Could not create directory <tgtDir.getAbsolutePath()>
- cp: omitting directory
- cp: cannot copy to directory
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/b1f03dfddc68483b.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/ie/crf/CRFClassifier.java:1646
evaluators = new Evaluator[evaluatorList.size()];
evaluatorList.toArray(evaluators);
}
if (flags.numTimesPruneFeatures == i) {
docs = null; // hopefully saves memory
}
// save feature index to disk and read in later
File featIndexFile = null;
// CRFLogConditionalObjectiveFunction.featureIndex = featureIndex;
// int numFeatures = featureIndex.size();
if (flags.saveFeatureIndexToDisk) {
try {
log.info("Writing feature index to temporary file.");
featIndexFile = IOUtils.writeObjectToTempFile(featureIndex, "featIndex" + i + ".tmp");
// featureIndex = null;
} catch (IOException e) {
throw new RuntimeException("Could not open temporary feature index file for writing.");
}
}
// first index is the number of the document
// second index is position in the document also the index of the
// clique/factor table
// third index is the number of elements in the clique/window these
// features are for (starting with last element)
// fourth index is position of the feature in the array that holds them
// element in data[i][j][k][m] is the index of the mth feature occurring
// in position k of the jth clique of the ith document
int[][][][] data = dataAndLabelsAndFeatureVals.first();
// first index is the number of the document
// second index is the position in the document
// element in labels[i][j] is the index of the correct label (if it
// exists) at position j in document i
int[][] labels = dataAndLabelsAndFeatureVals.second();
double[][][][] featureVals = dataAndLabelsAndFeatureVals.third();View on GitHub (pinned to 1b7edd19c4)