stanfordnlp/CoreNLP · error · java.io.IOException
Invalid number of fields, should be >=1 and <= 31
Error message
Invalid number of fields, should be >=1 and <= 31
What it means
edu.stanford.nlp.ie.pascal.Prior reads a model file whose first line lists up to 31 index fields; it throws this IOException when the header has fewer than 1 or more than 31 whitespace-separated fields. The field count determines the size of the joint probability matrix (2^n entries), so the parser enforces this bound to keep the matrix allocation sane.
Solutions
- Check the file's first line: it must contain between 1 and 31 whitespace-separated field names.
- Verify you are loading the correct Prior model file, not another format's file.
- Re-download or regenerate the model file if it is empty or truncated.
- If you genuinely need more than 31 fields, reduce the field set — the format cannot represent it.
Example fix
// before
Prior p = new Prior(new FileReader("empty_or_wrong.txt"));
// after
BufferedReader r = new BufferedReader(new FileReader("prior.model"));
String first = r.readLine();
int n = first == null ? 0 : first.trim().split("\\s+").length;
if (n < 1 || n > 31) throw new IOException("Bad Prior header, fields=" + n);
Prior p = new Prior(r); Defensive patterns
Strategy: validation
Validate before calling
// java: check the Prior header before constructing
String header = reader.readLine();
int n = (header == null || header.trim().isEmpty()) ? 0 : header.trim().split("\\s+").length;
if (n < 1 || n > 31) {
throw new IOException("Prior header has " + n + " fields; need 1-31");
} Try / catch
try {
Prior p = new Prior(reader);
} catch (IOException e) {
if (e.getMessage().contains("Invalid number of fields")) {
LOG.error("Wrong or corrupt Prior model file: " + e.getMessage());
p = loadFallbackPrior();
} else throw e;
} Prevention
- Verify model file provenance and format before loading; never point Prior at arbitrary text files.
- Checksum model files after download to catch truncation.
- Document the 1-31 field header limit wherever Prior models are created or edited.
When it happens
Trigger: Constructing Prior from a file whose first line is blank (0 fields) or contains more than 31 whitespace-separated field names, e.g. a corrupted or wrong-format model file passed to the Prior constructor.
Common situations: Pointing Prior at the wrong model file (a different format's file that happens to open); a truncated or empty model file from a failed download; editing a model file and adding fields beyond the 31-field hard limit.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- Error on line
- Found a non-empty line in a tsurgeon section after reading…
- Unknown minimizer
- Unknown clique: " + clique
- Bad number put into wordToNumber. Word is: \"" + input +…
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/1243dcfc049b1cc1.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/ie/pascal/Prior.java:35
private Map<String, Integer> fieldIndices;
private String[] indexFields;
// n-dimensional boolean matrix. There will be 2^n entries in the matrix.
private double[] matrix;
public Prior(BufferedReader reader) throws IOException {
String line;
line = reader.readLine();
if (line == null) {
throw new IOException();
}
indexFields = line.split("\\s+");
fieldIndices = new HashMap<String, Integer>();
for (int i = 0; i < indexFields.length; ++i) {
fieldIndices.put(indexFields[i], Integer.valueOf(i));
}
if (indexFields.length < 1 || indexFields.length > 31) {
throw new IOException("Invalid number of fields, should be >=1 and <= 31");
}
int matrixSize = 1 << indexFields.length;
matrix = new double[matrixSize];
int matrixIdx = 0;
while (matrixIdx < matrix.length && (line = reader.readLine()) != null) {
String[] tokens = line.split("\\s+");
for (int t = 0; matrixIdx < matrix.length && t < tokens.length; ++t) {
matrix[matrixIdx++] = Double.parseDouble(tokens[t]);
}
}
}
/**
* {@code Map<String, boolean>}
*/
public double get(Set presentFields) {
int index = 0;
for (String field : indexFields) {View on GitHub (pinned to 1b7edd19c4)