{"record":{"id":"d477820809414fb4","repo":"stanfordnlp/CoreNLP","slug":"constructor-argument-not-valid-list-of-number-rang","errorCode":null,"errorMessage":"Constructor argument not valid list of number ranges (too many hyphens): ","messagePattern":"Constructor argument not valid list of number ranges \\(too many hyphens\\): ","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/io/NumberRangesFileFilter.java","lineNumber":61,"sourceCode":"\n  /**\n   * Sets up a NumberRangesFileFilter by specifying the ranges of numbers\n   * to accept, and whether to also traverse\n   * folders for recursive search.\n   *\n   * @param ranges  The ranges of numbers to accept (see class documentation)\n   * @param recurse Whether to go into subfolders\n   * @throws IllegalArgumentException If the String ranges does not\n   *                                  contain a suitable ranges format\n   */\n  public NumberRangesFileFilter(String ranges, boolean recurse) {\n    recursively = recurse;\n    try {\n      String[] ra = ranges.split(\",\");\n      for (String range : ra) {\n        String[] one = range.split(\"-\");\n        if (one.length > 2) {\n          throw new IllegalArgumentException(\"Constructor argument not valid list of number ranges (too many hyphens): \");\n        } else {\n          int low = Integer.parseInt(one[0].trim());\n          int high;\n          if (one.length == 2) {\n            high = Integer.parseInt(one[1].trim());\n          } else {\n            high = low;\n          }\n          Pair<Integer, Integer> p = new Pair<>(Integer.valueOf(low), Integer.valueOf(high));\n          this.ranges.add(p);\n        }\n      }\n    } catch (Exception e) {\n      throw new IllegalArgumentException(\"Constructor argument not valid list of number ranges: \" + ranges, e);\n    }\n  }\n\n","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/io/NumberRangesFileFilter.java#L43-L79","documentation":"NumberRangesFileFilter parses a comma-separated string of number ranges like \"1-5,20,100-200\". Each comma-separated token may contain at most one hyphen; a token with more than one hyphen cannot be a valid range, so the constructor throws this IllegalArgumentException. The message notably omits the offending input string.","triggerScenarios":"new NumberRangesFileFilter(\"1-2-3\", false) or any ranges string where a comma-separated token splits on '-' into more than 2 pieces (e.g. negative-number-looking tokens like \"-1-5\").","commonSituations":"Negative range endpoints (\"-10--1\"), typos with extra hyphens, filenames/config values built by string concatenation that leaked an extra '-'.","solutions":["Remove the extra hyphen so each token is either \"N\" or \"N-M\" with non-negative integers","If negative bounds are needed, preprocess the string yourself and pass absolute values or a custom filter","Validate the ranges string with a regex like \\\\d+(-\\\\d+)?(,\\\\d+(-\\\\d+)?)* before constructing"],"exampleFix":"// before\nnew NumberRangesFileFilter(\"1-2-5\", false);\n// after\nnew NumberRangesFileFilter(\"1-5\", false);","handlingStrategy":"validation","validationCode":"if (!ranges.matches(\"\\\\d+(-\\\\d+)?(,\\\\s*\\\\d+(-\\\\d+)?)*\")) throw new IllegalArgumentException(\"Bad ranges: \" + ranges);","typeGuard":null,"tryCatchPattern":"try { f = new NumberRangesFileFilter(ranges, recurse); } catch (IllegalArgumentException e) { if (e.getMessage().contains(\"too many hyphens\")) { /* fix ranges string */ } else throw e; }","preventionTips":["Regex-validate range strings before constructing","Avoid negative numbers in range specs","Sanitize concatenated config values for stray hyphens"],"tags":["parsing","validation","filter"],"backgroundTag":"invalid-argument-format","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"}