{"record":{"id":"04e5b2c977a6c852","repo":"stanfordnlp/CoreNLP","slug":"to-length-to-length-from-length-from-l","errorCode":null,"errorMessage":"to length:\" + to.length + \" from length:\" + from.length","messagePattern":"to length:\" \\+ to\\.length \\+ \" from length:\" \\+ from\\.length","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/math/ArrayMath.java","lineNumber":302,"sourceCode":"    return result;\n  }\n\n  /**\n   * raises each entry in array a by power c\n   */\n  public static float[] pow(float[] a, float c) {\n    float[] result = new float[a.length];\n    for (int i = 0; i < a.length; i++) {\n      result[i] = (float) Math.pow(a[i], c);\n    }\n    return result;\n  }\n\n  // OPERATIONS WITH TWO ARRAYS - DESTRUCTIVE\n\n  public static void pairwiseAddInPlace(float[] to, float[] from) {\n    if (to.length != from.length) {\n      throw new IllegalArgumentException(\"to length:\" + to.length + \" from length:\" + from.length);\n    }\n    for (int i = 0; i < to.length; i++) {\n      to[i] += from[i];\n    }\n  }\n\n  /**\n   * Add the two 1d arrays in place of {@code to}.\n   *\n   * @throws java.lang.IllegalArgumentException If {@code to} and {@code from} are not of the same dimensions\n   */\n  public static void pairwiseAddInPlace(double[] to, double[] from) {\n    if (to.length != from.length) {\n      throw new IllegalArgumentException(\"to length:\" + to.length + \" from length:\" + from.length);\n    }\n    for (int i = 0; i < to.length; i++) {\n      to[i] += from[i];\n    }","sourceCodeStart":284,"sourceCodeEnd":320,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/math/ArrayMath.java#L284-L320","documentation":"The float[] overload of ArrayMath.pairwiseAddInPlace requires both arrays to have identical length, since it adds from[i] into to[i] element-wise. A length mismatch means the operation is undefined, so it throws IllegalArgumentException immediately with both lengths in the message.","triggerScenarios":"Calling ArrayMath.addInPlace or pairwiseAddInPlace(float[], float[]) with arrays produced from different models, different feature counts, or truncated/sliced arrays of unequal size.","commonSituations":"Mixing feature vectors from different feature alphabets; loading weights checkpointed with an older model version whose dimensionality changed.","solutions":["Check to.length == from.length before calling, or pad/trim the shorter array.","Rebuild one of the arrays from the same feature space/model version as the other.","Catch IllegalArgumentException and log both lengths to identify which pipeline stage produced the mismatched vector."],"exampleFix":"// before\nArrayMath.pairwiseAddInPlace(a, b); // a.length=10, b.length=9\n// after\nif (a.length == b.length) ArrayMath.pairwiseAddInPlace(a, b);","handlingStrategy":"validation","validationCode":"if (to.length != from.length) throw new IllegalArgumentException(\"cannot pairwise-add float arrays: \" + to.length + \" vs \" + from.length);","typeGuard":"boolean sameLength(float[] a, float[] b) { return a.length == b.length; }","tryCatchPattern":"try { ArrayMath.pairwiseAddInPlace(to, from); } catch (IllegalArgumentException e) { if (e.getMessage().startsWith(\"to length:\")) { /* resize or abort */ } else throw e; }","preventionTips":["Centralize vector creation so dimensions come from one source of truth","Version-check model artifacts against feature extractors","Assert array lengths in unit tests around vector math"],"tags":["java","arrays","dimension-mismatch"],"backgroundTag":"shape-mismatch","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"}