{"record":{"id":"b1f03dfddc68483b","repo":"stanfordnlp/CoreNLP","slug":"could-not-open-temporary-feature-index-file-for-wr","errorCode":null,"errorMessage":"Could not open temporary feature index file for writing.","messagePattern":"Could not open temporary feature index file for writing\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"critical","filePath":"src/edu/stanford/nlp/ie/crf/CRFClassifier.java","lineNumber":1646,"sourceCode":"        evaluators = new Evaluator[evaluatorList.size()];\n        evaluatorList.toArray(evaluators);\n      }\n\n      if (flags.numTimesPruneFeatures == i) {\n        docs = null; // hopefully saves memory\n      }\n      // save feature index to disk and read in later\n      File featIndexFile = null;\n\n      // CRFLogConditionalObjectiveFunction.featureIndex = featureIndex;\n      // int numFeatures = featureIndex.size();\n      if (flags.saveFeatureIndexToDisk) {\n        try {\n          log.info(\"Writing feature index to temporary file.\");\n          featIndexFile = IOUtils.writeObjectToTempFile(featureIndex, \"featIndex\" + i + \".tmp\");\n          // featureIndex = null;\n        } catch (IOException e) {\n          throw new RuntimeException(\"Could not open temporary feature index file for writing.\");\n        }\n      }\n\n      // first index is the number of the document\n      // second index is position in the document also the index of the\n      // clique/factor table\n      // third index is the number of elements in the clique/window these\n      // features are for (starting with last element)\n      // fourth index is position of the feature in the array that holds them\n      // element in data[i][j][k][m] is the index of the mth feature occurring\n      // in position k of the jth clique of the ith document\n      int[][][][] data = dataAndLabelsAndFeatureVals.first();\n      // first index is the number of the document\n      // second index is the position in the document\n      // element in labels[i][j] is the index of the correct label (if it\n      // exists) at position j in document i\n      int[][] labels = dataAndLabelsAndFeatureVals.second();\n      double[][][][] featureVals = dataAndLabelsAndFeatureVals.third();","sourceCodeStart":1628,"sourceCodeEnd":1664,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ie/crf/CRFClassifier.java#L1628-L1664","documentation":"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.","triggerScenarios":"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.","commonSituations":"Read-only or full /tmp on shared servers and containers; restrictive tmpdir; sandboxed CI environments with no temp write access.","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."],"exampleFix":"// before\njava -Djava.io.tmpdir=/nonexistent -cp ... edu.stanford.nlp.ie.crf.CRFClassifier ...\n// after\njava -Djava.io.tmpdir=/data/tmp -cp ... edu.stanford.nlp.ie.crf.CRFClassifier ...\n// or remove saveFeatureIndexToDisk=true from the properties","handlingStrategy":"try-catch","validationCode":"File tmpDir = new File(System.getProperty(\"java.io.tmpdir\"));\nif (!tmpDir.canWrite() || tmpDir.getUsableSpace() < 100L * 1024 * 1024) {\n  throw new IllegalStateException(\"tmpdir not writable or low on space: \" + tmpDir);\n}\n// or simply don't set saveFeatureIndexToDisk=true when the index fits in memory","typeGuard":null,"tryCatchPattern":"try {\n  classifier.train(files);\n} catch (RuntimeException e) {\n  if (String.valueOf(e.getMessage()).contains(\"temporary feature index file for writing\")) {\n    props.remove(\"saveFeatureIndexToDisk\"); // keep index in memory\n    // rebuild classifier and retry, or fix tmpdir first\n  } else throw e;\n}","preventionTips":["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."],"tags":["java","io","filesystem","temp-file"],"backgroundTag":"file-write-failed","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}