{"record":{"id":"763367c71e2221f3","repo":"stanfordnlp/CoreNLP","slug":"name-and-weight-arrays-must-be-of-the-same-length","errorCode":null,"errorMessage":"Name and weight arrays must be of the same length","messagePattern":"Name and weight arrays must be of the same length","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/trees/SplitTrainingSet.java","lineNumber":68,"sourceCode":"    int index = 0;\n    for (Double weight : weights) {\n      offset = offset - weight;\n      if (offset < 0.0) {\n        return index;\n      }\n      index = index + 1;\n    }\n    return weights.size() - 1;\n  }\n\n  @SuppressWarnings(\"unused\")\n  public static void main(String[] args) throws IOException {\n    // Parse the arguments\n    Properties props = StringUtils.argsToProperties(args);\n    ArgumentParser.fillOptions(new Class[]{ArgumentParser.class, SplitTrainingSet.class}, props);\n\n    if (SPLIT_NAMES.length != SPLIT_WEIGHTS.length) {\n      throw new IllegalArgumentException(\"Name and weight arrays must be of the same length\");\n    }\n\n    double totalWeight = 0.0;\n    for (Double weight : SPLIT_WEIGHTS) {\n      totalWeight += weight;\n      if (weight < 0.0) {\n        throw new IllegalArgumentException(\"Split weights cannot be negative\");\n      }\n    }\n\n    if (totalWeight <= 0.0) {\n      throw new IllegalArgumentException(\"Split weights must total to a positive weight\");\n    }\n\n    List<Double> splitWeights = new ArrayList<>();\n    for (Double weight : SPLIT_WEIGHTS) {\n      splitWeights.add(weight / totalWeight);\n    }","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/trees/SplitTrainingSet.java#L50-L86","documentation":"SplitTrainingSet splits a treebank into named subsets by weights; it validates that the SPLIT_NAMES and SPLIT_WEIGHTS option arrays have equal length. When the number of split names differs from the number of weights, main throws this IllegalArgumentException at startup.","triggerScenarios":"Invoking SplitTrainingSet.main (or filling its options) with properties where splitNames and splitWeights have different cardinalities — e.g. three names but two weights, or a weight string with a malformed/dropped element after comma splitting.","commonSituations":"Editing a properties/config file and adding a split name without adding its weight (or vice versa); trailing/extra commas producing an empty name entry; programmatically building the arrays with unequal lengths.","solutions":["Make splitNames and splitWeights contain the same number of comma-separated elements in the properties passed via -splitNames/-splitWeights.","Check for stray or missing commas that shift element counts.","Add an explicit weight for each named split (weights need not sum to 1 but must be positive in total)."],"exampleFix":"// before\n-splitNames train,dev,test -splitWeights 0.8,0.2\n// after\n-splitNames train,dev,test -splitWeights 0.8,0.1,0.1","handlingStrategy":"validation","validationCode":"String[] names = props.getProperty(\"splitNames\", \"\").split(\",\");\ndouble[] ws = Arrays.stream(props.getProperty(\"splitWeights\", \"\").split(\",\"))\n                    .mapToDouble(Double::parseDouble).toArray();\nif (names.length != ws.length)\n  throw new IllegalArgumentException(\"splitNames and splitWeights must have equal counts\");","typeGuard":null,"tryCatchPattern":"try {\n  SplitTrainingSet.main(args);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"same length\")) {\n    log.error(\"Config error: provide one weight per split name\");\n  } else throw e;\n}","preventionTips":["Keep split names and weights defined together in one config block so they stay in sync.","Count entries after comma-splitting when editing properties files.","Add a smoke test that builds the options and calls the validation path."],"tags":["cli","configuration","argument-validation","dataset-split"],"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"}