{"record":{"id":"71b3290570f5d732","repo":"stanfordnlp/CoreNLP","slug":"invalid-arguments-to-name","errorCode":null,"errorMessage":"Invalid arguments to ${name}","messagePattern":"Invalid arguments to (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/time/GenericTimeExpressionPatterns.java","lineNumber":166,"sourceCode":"              public boolean checkArgs(List<Value> in) {\n                // TODO: Check args\n                return true;\n              }\n              public Value apply(Env env, List<Value> in) {\n                if (in.size() == 2) {\n                  SUTime.Duration d = (SUTime.Duration) in.get(0).get();\n                  if (in.get(1).get() instanceof Number) {\n                    int m = ((Number) in.get(1).get()).intValue();\n                    return new Expressions.PrimitiveValue(\"DURATION\", d.multiplyBy(m));\n                  } else if (in.get(1).get() instanceof String){\n                    Number n = Integer.parseInt((String) in.get(1).get());\n                    if (n != null) {\n                      return new Expressions.PrimitiveValue(\"DURATION\", d.multiplyBy(n.intValue()));\n                    } else {\n                      return null;\n                    }\n                  } else {\n                    throw new IllegalArgumentException(\"Invalid arguments to \" + name);\n                  }\n                } else if (in.size() == 5 || in.size() == 3) {\n                  // TODO: Handle Strings...\n                  List<? extends CoreMap> durationStartTokens = (List<? extends CoreMap>) in.get(0).get();\n                  Number durationStartVal = (durationStartTokens != null)? durationStartTokens.get(0).get(CoreAnnotations.NumericCompositeValueAnnotation.class):null;\n                  List<? extends CoreMap> durationEndTokens = (List<? extends CoreMap>) in.get(1).get();\n                  Number durationEndVal = (durationEndTokens != null)? durationEndTokens.get(0).get(CoreAnnotations.NumericCompositeValueAnnotation.class):null;\n                  // TODO: This should already be in durations....\n                  List<? extends CoreMap> durationUnitTokens = (List<? extends CoreMap>) in.get(2).get();\n                  //String durationUnitString = (durationUnitTokens != null)? durationUnitTokens.get(0).get(CoreAnnotations.TextAnnotation.class):null;\n                  //SUTime.Duration durationUnit = getDuration(durationUnitString);\n                  TimeExpression te = (durationUnitTokens != null)? durationUnitTokens.get(0).get(TimeExpression.Annotation.class):null;\n                  SUTime.Duration durationUnit = (SUTime.Duration) te.getTemporal();\n\n                  // TODO: Handle inexactness\n                  // Create duration range...\n                  SUTime.Duration durationStart = (durationStartVal != null)? durationUnit.multiplyBy(durationStartVal.intValue()):null;\n                  SUTime.Duration durationEnd = (durationEndVal != null)? durationUnit.multiplyBy(durationEndVal.intValue()):null;","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/time/GenericTimeExpressionPatterns.java#L148-L184","documentation":"GenericTimeExpressionPatterns' functional expressions (duration/time arithmetic like ISODurOperations) validate the number and types of arguments passed by the expression evaluator. When a composed expression such as a duration operation receives arguments (the `in` list) that do not match any supported arity/type combination (e.g. size 4, or wrong element types), it throws IllegalArgumentException 'Invalid arguments to <name>'.","triggerScenarios":"A time expression pattern's option/functional expression calls an operation (e.g. duration offset arithmetic) with an argument list whose size or element types are unsupported — typically from a custom or edited patterns file (tokensregex/semgrex options) that invokes the operation with the wrong argument count or a non-numeric argument where a Number is expected.","commonSituations":"Editing the default SUTime patterns (defs/patterns) to add custom duration expressions; passing a String where a numeric composite value is expected; pattern grammar changes across CoreNLP versions making an expression emit a different argument arity.","solutions":["Inspect which operation `name` failed and count the arguments the pattern supplies; correct the arity (supported sizes are checked in the code, e.g. 5 or 3)","Verify each argument's expected type (numeric composite value / Number) in your custom pattern and fix non-numeric inputs","Revert to the stock SUTime patterns file bundled with your CoreNLP version to confirm the pattern is the cause","Upgrade/align the patterns file with your CoreNLP version — mismatched patterns are a frequent cause"],"exampleFix":"// before\n// custom pattern passes 4 args to duration op\n$durationOffset = ( { numcomptype:DURATION } ) (?: with ) ( { numcomptype:NUMBER } ) (?: offset ) ;\n// after\n// supply the supported 3- or 5-argument form\n$durationOffset = ( { numcomptype:DURATION } ) (?: from ) ( { numcomptype:DURATION } ) ;","handlingStrategy":"try-catch","validationCode":"// Validate custom pattern operations against supported arities before running the pipeline\n// (offline check in a unit test)\n@Test\nvoid durationOpsHaveValidArity() {\n  // ensure any operation invocation in the patterns file uses 3 or 5 arguments\n  // and that numeric operands come from numcomptype:NUMBER captures\n}","typeGuard":"// Java: verify numeric operand before invoking duration operations\nstatic boolean validDurationOpArgs(java.util.List<Expressions.Expression> in) {\n  return in.size() == 3 || in.size() == 5; // supported arities\n}","tryCatchPattern":"try {\n  pipeline.annotate(annotation);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage() != null && e.getMessage().startsWith(\"Invalid arguments to\")) {\n    logger.severe(\"Bad SUTime pattern invocation: \" + e.getMessage());\n    // fall back to stock patterns file\n  } else throw e;\n}","preventionTips":["Do not hand-edit SUTime patterns without checking each functional expression's expected argument count/types","Run a small corpus through the pipeline in CI to catch pattern regressions early","Keep the patterns file and CoreNLP jar versions in sync","Quote numeric operands with numcomptype:NUMBER so operations receive Number values, not Strings"],"tags":["java","nlp","sutime","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"}