{"record":{"id":"94d8535305e16638","repo":"stanfordnlp/CoreNLP","slug":"constructor-argument-not-valid-list-of-number-rang-94d853","errorCode":null,"errorMessage":"Constructor argument not valid list of number ranges: <ranges>","messagePattern":"Constructor argument not valid list of number ranges: <ranges>","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/io/NumberRangesFileFilter.java","lineNumber":75,"sourceCode":"      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\n  /**\n   * Checks whether a file satisfies the number range selection filter.\n   * The test is evaluated based on the rightmost natural number found in\n   * the filename string (proper, not including directories in a path).\n   *\n   * @param file The file\n   * @return true If the file is within the ranges filtered for\n   */\n  public boolean accept(File file) {\n    if (file.isDirectory()) {\n      return recursively;\n    } else {\n      String filename = file.getName();\n      return accept(filename);","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/io/NumberRangesFileFilter.java#L57-L93","documentation":"The constructor wraps its whole range-parsing loop in a catch-all; any Exception while parsing (NumberFormatException from a non-integer token, ArrayIndexOutOfBounds from an empty token) is rethrown as this IllegalArgumentException with the original ranges string and cause attached.","triggerScenarios":"new NumberRangesFileFilter(\"1,a-5,,20\", false) — any token that fails Integer.parseInt or is empty after trimming.","commonSituations":"Config/property values with typos or whitespace artifacts, empty entries from trailing commas, format mistakes like \"1 to 5\" instead of \"1-5\".","solutions":["Inspect the cause (getCause()) to find the offending token and fix the ranges string to only contain integers and hyphens","Pre-validate with a regex \\\\d+(-\\\\d+)?(,\\\\s*\\\\d+(-\\\\d+)?)* and reject bad input with your own message","Trim/split defensively: strip spaces, drop empty tokens before constructing the filter"],"exampleFix":"// before\nnew NumberRangesFileFilter(\"1, 2-5, ,8\", false); // empty token -> NumberFormatException\n// after\nString ranges = \"1, 2-5, ,8\";\nif (!ranges.matches(\"\\\\d+(-\\\\d+)?(,\\\\s*\\\\d+(-\\\\d+)?)*\")) {\n  throw new IllegalArgumentException(\"Bad ranges: \" + ranges);\n}\nnew NumberRangesFileFilter(ranges, false);","handlingStrategy":"try-catch","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) { log.severe(\"Bad ranges '\" + ranges + \"': \" + e.getCause()); throw e; }","preventionTips":["Always check getCause() to identify the bad token","Trim and drop empty tokens after splitting on commas","Validate user/config-supplied range strings before parsing"],"tags":["parsing","validation","number-format"],"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-15T23:17:13.987Z"}