{"record":{"id":"1243dcfc049b1cc1","repo":"stanfordnlp/CoreNLP","slug":"invalid-number-of-fields-should-be-1-and-31","errorCode":null,"errorMessage":"Invalid number of fields, should be >=1 and <= 31","messagePattern":"Invalid number of fields, should be >=1 and <= 31","errorType":"exception","errorClass":"java.io.IOException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/ie/pascal/Prior.java","lineNumber":35,"sourceCode":"  private Map<String, Integer> fieldIndices;\n  private String[] indexFields;\n\n  // n-dimensional boolean matrix. There will be 2^n entries in the matrix.\n  private double[] matrix;\n\n  public Prior(BufferedReader reader) throws IOException {\n    String line;\n    line = reader.readLine();\n    if (line == null) {\n      throw new IOException();\n    }\n    indexFields = line.split(\"\\\\s+\");\n    fieldIndices = new HashMap<String, Integer>();\n    for (int i = 0; i < indexFields.length; ++i) {\n      fieldIndices.put(indexFields[i], Integer.valueOf(i));\n    }\n    if (indexFields.length < 1 || indexFields.length > 31) {\n      throw new IOException(\"Invalid number of fields, should be >=1 and <= 31\");\n    }\n    int matrixSize = 1 << indexFields.length;\n    matrix = new double[matrixSize];\n    int matrixIdx = 0;\n    while (matrixIdx < matrix.length && (line = reader.readLine()) != null) {\n      String[] tokens = line.split(\"\\\\s+\");\n      for (int t = 0; matrixIdx < matrix.length && t < tokens.length; ++t) {\n        matrix[matrixIdx++] = Double.parseDouble(tokens[t]);\n      }\n    }\n  }\n\n  /**\n   * {@code Map<String, boolean>}\n   */\n  public double get(Set presentFields) {\n    int index = 0;\n    for (String field : indexFields) {","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ie/pascal/Prior.java#L17-L53","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nPrior p = new Prior(new FileReader(\"empty_or_wrong.txt\"));\n// after\nBufferedReader r = new BufferedReader(new FileReader(\"prior.model\"));\nString first = r.readLine();\nint n = first == null ? 0 : first.trim().split(\"\\\\s+\").length;\nif (n < 1 || n > 31) throw new IOException(\"Bad Prior header, fields=\" + n);\nPrior p = new Prior(r);","handlingStrategy":"validation","validationCode":"// java: check the Prior header before constructing\nString header = reader.readLine();\nint n = (header == null || header.trim().isEmpty()) ? 0 : header.trim().split(\"\\\\s+\").length;\nif (n < 1 || n > 31) {\n  throw new IOException(\"Prior header has \" + n + \" fields; need 1-31\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  Prior p = new Prior(reader);\n} catch (IOException e) {\n  if (e.getMessage().contains(\"Invalid number of fields\")) {\n    LOG.error(\"Wrong or corrupt Prior model file: \" + e.getMessage());\n    p = loadFallbackPrior();\n  } else throw e;\n}","preventionTips":["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."],"tags":["java","file-parsing","model-file","nlp"],"backgroundTag":"schema-validation-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"}