{"record":{"id":"97f9155aa8676261","repo":"stanfordnlp/CoreNLP","slug":"nargs-arguments-expected-got-in-size","errorCode":null,"errorMessage":"${nargs} arguments expected, got ${in.size()}","messagePattern":"(.+?) arguments expected, got (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/ling/tokensregex/types/ValueFunctions.java","lineNumber":184,"sourceCode":"    public abstract Number compute(Number...ns);\n\n    @Override\n    public boolean checkArgs(List<Value> in) {\n      if (nargs > 0 && in.size() != nargs) {\n        return false;\n      }\n      for (Value v : in) {\n        if (v == null || !(v.get() instanceof Number)) {\n          return false;\n        }\n      }\n      return true;\n    }\n\n    @Override\n    public Value apply(Env env, List<Value> in) {\n      if (nargs > 0 && in.size() != nargs) {\n        throw new IllegalArgumentException(nargs + \" arguments expected, got \" + in.size());\n      }\n      Number[] numbers = new Number[in.size()];\n      for (int i = 0; i < in.size(); i++) {\n        numbers[i] = (Number) in.get(i).get();\n      }\n      Number res = compute(numbers);\n      return new Expressions.PrimitiveValue(resultTypeName, res);\n    }\n  }\n\n  public static final ValueFunction ADD_FUNCTION = new NumericFunction(\"ADD\", 2) {\n    @Override\n    public Number compute(Number... in) {\n      if (isInteger(in[0]) && isInteger(in[1])) {\n        return in[0].longValue() + in[1].longValue();\n      } else {\n        return in[0].doubleValue() + in[1].doubleValue();\n      }","sourceCodeStart":166,"sourceCodeEnd":202,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ling/tokensregex/types/ValueFunctions.java#L166-L202","documentation":"ValueFunctions.NumericFunction.apply validates argument count before computing: if the function declares a fixed nargs > 0 and the incoming list size differs, it throws this IllegalArgumentException. It enforces arity for numeric functions (e.g. MIN/MAX with fixed argument counts) in TokensRegex expressions.","triggerScenarios":"Calling a TokensRegex numeric function (e.g. in a rule's action or expression) with the wrong number of arguments — too few from missing bindings, too many from extra comma-separated expressions; binding list built programmatically with wrong size.","commonSituations":"Rule expressions like FUNC{...} where the expected fixed arity doesn't match; captured-groups list feeding a numeric function with a variable count; miscounted arguments after editing a rule.","solutions":["Count the function's required arguments and supply exactly nargs values in the call.","Log/inspect in.size() from the exception message to see how many were actually passed and where the extras/missing ones come from.","If arguments come from capture groups, guard with a count check before invoking the function.","Use a variadic function (nargs == -1 / nargs <= 0 path) if a variable argument count is intended."],"exampleFix":"// before\nMIN()               // 0 args, function requires 2\n// after\nMIN($left, $right)  // matches nargs == 2","handlingStrategy":"validation","validationCode":"if (args.size() != expectedNargs) {\n  throw new IllegalStateException(\"MIN/MAX function needs \" + expectedNargs + \" args, got \" + args.size());\n}","typeGuard":"static boolean hasArity(java.util.List<?> in, int nargs) {\n  return nargs <= 0 || in.size() == nargs;\n}","tryCatchPattern":"try { Value v = func.apply(env, in); }\ncatch (IllegalArgumentException ex) {\n  if (ex.getMessage().contains(\"arguments expected, got\")) {\n    log.error(\"Arity mismatch calling numeric function: \" + ex.getMessage());\n  }\n  throw ex;\n}","preventionTips":["Check the function's declared nargs before calling","Count arguments in rule expressions carefully after edits","Guard dynamic argument lists (capture groups) with size checks"],"tags":["arity","argument-count","tokensregex","valuefunctions"],"backgroundTag":"missing-required-argument","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"}