{"record":{"id":"82ccbdf5b245f715","repo":"stanfordnlp/CoreNLP","slug":"invalid-projection-function-arrays-tostring-p","errorCode":null,"errorMessage":"Invalid projection function: \" + Arrays.toString(projectionFunction)","messagePattern":"Invalid projection function: \" \\+ Arrays\\.toString\\(projectionFunction\\)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/naturalli/Polarity.java","lineNumber":51,"sourceCode":"      }\n    } else {\n      for (int rel = 0; rel < 7; ++rel) {\n        NaturalLogicRelation relation = NaturalLogicRelation.byFixedIndex(rel);\n        for (int op = operatorsInNarrowingScopeOrder.size() - 1; op >= 0; --op) {\n          relation = project(relation, operatorsInNarrowingScopeOrder.get(op).first, operatorsInNarrowingScopeOrder.get(op).second);\n        }\n        projectionFunction[rel] = (byte) relation.fixedIndex;\n      }\n    }\n  }\n\n  /**\n   * Create a polarity item by directly copying the projection function from {@link edu.stanford.nlp.naturalli.NaturalLogicRelation}s to\n   * their projected relation.\n   */\n  public Polarity(byte[] projectionFunction) {\n    if (projectionFunction.length != 7) {\n      throw new IllegalArgumentException(\"Invalid projection function: \" + Arrays.toString(projectionFunction));\n    }\n    for (int i = 0; i < 7; ++i) {\n      if (projectionFunction[i] < 0 || projectionFunction[i] > 6) {\n        throw new IllegalArgumentException(\"Invalid projection function: \" + Arrays.toString(projectionFunction));\n      }\n    }\n    System.arraycopy(projectionFunction, 0, this.projectionFunction, 0, 7);\n  }\n\n  /**\n   * Encode the projection table in painful detail.\n   *\n   * @param input The input natural logic relation to project up through the operator.\n   * @param mono The monotonicity of the operator we are projecting through.\n   * @param type The monotonicity type of the operator we are projecting through.\n   *\n   * @return The projected relation, once passed through an operator with the given specifications.\n   */","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/naturalli/Polarity.java#L33-L69","documentation":"The Polarity(byte[]) constructor validates that the projection function array is exactly length 7 (one slot per NaturalLogicRelation) before using it. If the caller supplies an array of any other length, it throws IllegalArgumentException reporting the offending array. The length 7 corresponds to the seven natural-logic relations the projection table must cover.","triggerScenarios":"new Polarity(byte[]) with an array whose length != 7 — e.g. a hand-written projection table, a truncated byte[] read from a model file, or an array built from an older relation enum with a different cardinality.","commonSituations":"Hand-crafting custom polarity/projection tables; deserializing serialized Polarity data produced by a different CoreNLP version where the relation count changed.","solutions":["Ensure the array passed to the constructor has exactly 7 entries, indexed by NaturalLogicRelation ordinal","Pad or truncate a shorter/longer source array to 7 before constructing, mapping old ordinals correctly","Check version compatibility of any serialized projection data"],"exampleFix":"// before\nPolarity p = new Polarity(myTable); // myTable.length == 5\n// after\nbyte[] table = new byte[7];\nSystem.arraycopy(myTable, 0, table, 0, Math.min(myTable.length, 7));\nPolarity p = new Polarity(table);","handlingStrategy":"validation","validationCode":"if (fn == null || fn.length != 7) throw new IllegalArgumentException(\"projection table must have 7 entries, got \" + (fn == null ? \"null\" : fn.length));","typeGuard":null,"tryCatchPattern":"try { new Polarity(fn); } catch (IllegalArgumentException e) { /* rebuild table from NaturalLogicRelation ordinals */ }","preventionTips":["Always build projection tables indexed by NaturalLogicRelation ordinal","Validate serialized data lengths before constructing Polarity"],"tags":["java","illegal-argument","array-length"],"backgroundTag":"invalid-argument-value","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}