{"record":{"id":"6bfc6fdaf797e2b7","repo":"stanfordnlp/CoreNLP","slug":"invalid-value-value-for-type-typename","errorCode":null,"errorMessage":"Invalid value ${value} for type ${typeName}","messagePattern":"Invalid value (.+?) for type (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/ling/tokensregex/types/Expressions.java","lineNumber":1342,"sourceCode":"            }\n            case TYPE_STRING:\n              return new PrimitiveValue<>(TYPE_STRING, (String) value.get());\n            case TYPE_REGEX:\n              return new RegexValue((String) value.get());\n            /* } else if (TYPE_TOKEN_REGEX.equals(type)) {\n       return new PrimitiveValue<TokenSequencePattern>(TYPE_TOKEN_REGEX, (TokenSequencePattern) value.get()); */\n            case TYPE_NUMBER:\n              if (value.get() instanceof Number) {\n                return new PrimitiveValue<>(TYPE_NUMBER, (Number) value.get());\n              } else if (value.get() instanceof String) {\n                String str = (String) value.get();\n                if (str.contains(\".\")) {\n                  return new PrimitiveValue<Number>(TYPE_NUMBER, Double.valueOf(str));\n                } else {\n                  return new PrimitiveValue<Number>(TYPE_NUMBER, Long.valueOf(str));\n                }\n              } else {\n                throw new IllegalArgumentException(\"Invalid value \" + value + \" for type \" + typeName);\n              }\n            default:\n              // TODO: support other types\n              return new PrimitiveValue(typeName, value.get());\n              //throw new UnsupportedOperationException(\"Cannot convert type \" + typeName);\n          }\n        }\n      }\n      return null;\n    }\n\n    public CompositeValue simplifyNoTypeConversion(Env env, Object... args) {\n      Map<String, Expression> m = value;\n      Map<String, Expression> res = new HashMap<>(m.size());//Generics.newHashMap (m.size());\n      for (Map.Entry<String, Expression> stringExpressionEntry : m.entrySet()) {\n        res.put(stringExpressionEntry.getKey(), stringExpressionEntry.getValue().simplify(env));\n      }\n      return new CompositeValue(res, true);","sourceCodeStart":1324,"sourceCodeEnd":1360,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ling/tokensregex/types/Expressions.java#L1324-L1360","documentation":"When a typed value with TYPE \"NUMBER\" is evaluated, the string must parse as Long or Double. If the stored value's string contains characters that break numeric parsing, or the value is not a String/Number at all, the evaluator throws this IllegalArgumentException naming the value and requested type.","triggerScenarios":"Evaluating (NUMBER) { value: \"12abc\" } or a non-numeric string; whitespace/locale characters (e.g. comma decimal separator); passing a non-String object to a NUMBER-typed value.","commonSituations":"Rule authors putting units or text in numeric fields (\"3px\", \"1,5\"), capture-group substitutions that yield empty or partial strings at match time.","solutions":["Ensure the string is a valid Java numeric literal: digits with optional '.' and sign; strip units/symbols first.","Use '.' for decimals (Long if no dot, Double if dot) — replace locale commas with dots before evaluation.","Trim the string; empty/whitespace strings will fail parsing.","If the value comes from a capture group, validate it matches -?\\d+(\\.\\d+)? before feeding it into a NUMBER-typed value."],"exampleFix":"// before\n(NUMBER) { value: \"3px\" }\n// after\n(NUMBER) { value: \"3\" }  // or Double: (NUMBER) { value: \"3.0\" }","handlingStrategy":"validation","validationCode":"static boolean isNumericLiteral(String s) {\n  return s != null && s.trim().matches(\"-?\\\\d+(\\\\.\\\\d+)?\");\n}","typeGuard":"static boolean isValidNumberValue(Object v) {\n  if (v instanceof Number) return true;\n  return v instanceof String && ((String) v).trim().matches(\"-?\\\\d+(\\\\.\\\\d+)?\");\n}","tryCatchPattern":"try { Value<?> v = numberExpr.evaluate(env, args); }\ncatch (IllegalArgumentException ex) {\n  if (ex.getMessage().startsWith(\"Invalid value\")) {\n    throw new IllegalArgumentException(\"NUMBER-typed value must parse as Long/Double: \" + ex.getMessage(), ex);\n  }\n  throw ex;\n}","preventionTips":["Regex-validate numeric strings before typing them as NUMBER","Strip units/currency symbols and normalize decimal separators","Trim capture-group substitutions that feed NUMBER values"],"tags":["number-format","parsing","tokensregex","invalid-argument"],"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"}