{"record":{"id":"175fd352bfe90026","repo":"stanfordnlp/CoreNLP","slug":"invalid-minmatch","errorCode":null,"errorMessage":"Invalid minMatch=","messagePattern":"Invalid minMatch=","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/ling/tokensregex/SequencePattern.java","lineNumber":743,"sourceCode":"  }\n\n  /**  Expression that represents a pattern that repeats for a number of times. */\n  public static class RepeatPatternExpr extends PatternExpr {\n\n    private static final long serialVersionUID = 3935482630250147745L;\n\n    private final PatternExpr pattern;\n    private final int minMatch;\n    private final int maxMatch;\n    private final boolean greedyMatch;\n\n    public RepeatPatternExpr(PatternExpr pattern, int minMatch, int maxMatch) {\n      this(pattern, minMatch, maxMatch, true);\n    }\n\n    public RepeatPatternExpr(PatternExpr pattern, int minMatch, int maxMatch, boolean greedy) {\n      if (minMatch < 0) {\n        throw new IllegalArgumentException(\"Invalid minMatch=\" + minMatch);\n      }\n      if (maxMatch >= 0 && minMatch > maxMatch) {\n        throw new IllegalArgumentException(\"Invalid minMatch=\" + minMatch + \", maxMatch=\" + maxMatch);\n      }\n      this.pattern = pattern;\n      this.minMatch = minMatch;\n      this.maxMatch = maxMatch;\n      this.greedyMatch = greedy;\n    }\n\n    @Override\n    protected Frag build()\n    {\n      Frag f = pattern.build();\n      if (minMatch == 1 && maxMatch == 1) {\n        return f;\n      } else if (minMatch <= 5 && maxMatch <= 5 && greedyMatch) {\n        // Make copies if number of matches is low","sourceCodeStart":725,"sourceCodeEnd":761,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ling/tokensregex/SequencePattern.java#L725-L761","documentation":"SequencePattern.RepeatPatternExpr's 3-arg constructor delegates to the greedy 4-arg constructor, which throws IllegalArgumentException when minMatch is negative. A repeat expression cannot require a negative number of matches, so the library rejects it at pattern-build time. Note the same message is also thrown when minMatch exceeds a non-negative maxMatch.","triggerScenarios":"Calling new SequencePattern.RepeatPatternExpr(pattern, minMatch, maxMatch) with minMatch < 0, or with minMatch > maxMatch when maxMatch >= 0.","commonSituations":"Computing repetition bounds from user input or regex-translation code where a '?'/'{0,n}' style quantifier is mis-encoded as a negative minimum; off-by-one sign errors when converting (min,max) range specifications.","solutions":["Clamp or correct minMatch to be >= 0 before constructing the RepeatPatternExpr.","Verify the caller passing minMatch is not passing an error sentinel (-1) or an uninitialized value.","If the pattern is truly optional, use minMatch 0 instead of a negative value.","Check that minMatch <= maxMatch whenever maxMatch is a non-negative bound."],"exampleFix":"// before\nSequencePattern.RepeatPatternExpr r =\n    new SequencePattern.RepeatPatternExpr(wordPattern, minReps, maxReps);\n// after\nif (minReps < 0 || (maxReps >= 0 && minReps > maxReps)) {\n    throw new IllegalArgumentException(\"bad repeat bounds: \" + minReps + \",\" + maxReps);\n}\nSequencePattern.RepeatPatternExpr r =\n    new SequencePattern.RepeatPatternExpr(wordPattern, Math.max(0, minReps), maxReps);","handlingStrategy":"validation","validationCode":"if (minMatch < 0 || (maxMatch >= 0 && minMatch > maxMatch)) {\n    throw new IllegalArgumentException(\"repeat bounds out of range: min=\" + minMatch + \" max=\" + maxMatch);\n}","typeGuard":"static boolean isValidRepeatBounds(int minMatch, int maxMatch) {\n    return minMatch >= 0 && (maxMatch < 0 || minMatch <= maxMatch);\n}","tryCatchPattern":"try {\n    RepeatPatternExpr r = new RepeatPatternExpr(pattern, minMatch, maxMatch);\n} catch (IllegalArgumentException e) {\n    // log and fall back to a default pattern\n}","preventionTips":["Never use negative sentinels for minMatch; use 0 for optional and maxMatch=-1 for unbounded.","Validate repeat bounds at the config/CLI boundary before building patterns.","Write unit tests for bound-validation of every custom pattern builder."],"tags":["java","tokensregex","pattern-construction","illegal-argument"],"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-15T23:17:13.987Z"}