{"record":{"id":"6fc5117cc800b199","repo":"stanfordnlp/CoreNLP","slug":"unknown-class-classname","errorCode":null,"errorMessage":"Unknown class ${className}","messagePattern":"Unknown class (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/ling/tokensregex/types/Expressions.java","lineNumber":1314,"sourceCode":"                  return new PrimitiveValue<>(typeName, m.invoke(typeValue.get(), evaluatedCv));\n                } catch (InvocationTargetException | IllegalAccessException ex) {\n                  throw new RuntimeException(\"Cannot instantiate \" + c, ex);\n                }\n              } catch (NoSuchMethodException ex) {}\n            }\n          }\n        } else if (typeValue != null && typeValue.get() instanceof String) {\n          String typeName = (String) typeValue.get();\n          // Predefined types:\n          Expression valueField = cv.value.get(\"value\");\n          Value value = valueField.evaluate(env, args);\n          switch (typeName) {\n            case TYPE_ANNOTATION_KEY: {\n              String className = (String) value.get();\n              try {\n                return new PrimitiveValue<Class>(TYPE_ANNOTATION_KEY, Class.forName(className));\n              } catch (ClassNotFoundException ex) {\n                throw new RuntimeException(\"Unknown class \" + className, ex);\n              }\n            }\n            case TYPE_CLASS: {\n              String className = (String) value.get();\n              try {\n                return new PrimitiveValue<Class>(TYPE_CLASS, Class.forName(className));\n              } catch (ClassNotFoundException ex) {\n                throw new RuntimeException(\"Unknown class \" + className, ex);\n              }\n            }\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) {","sourceCodeStart":1296,"sourceCodeEnd":1332,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ling/tokensregex/types/Expressions.java#L1296-L1332","documentation":"When a TYPE \"CLASS\"/annotation-key value is evaluated, the stored string is loaded via Class.forName. If no class with that name is on the classpath, ClassNotFoundException is wrapped in this RuntimeException with the offending class name. It exists to fail fast on unresolvable class names inside TokensRegex expressions.","triggerScenarios":"Evaluating a composite/typed value with TYPE \"CLASS\" and a class name string that is misspelled, not fully qualified (missing package), or not on the runtime classpath; referencing CoreNLP classes whose packages changed across versions.","commonSituations":"Rules specifying edu.stanford.nlp.ling.CoreAnnotations$SomeAnnotation keys; typos in inner-class $ separators; custom annotation classes not included in the deployment jar; package refactors between CoreNLP versions.","solutions":["Use the fully qualified class name including package and $ for inner classes (e.g. edu.stanford.nlp.ling.CoreAnnotations$Tokens).","Verify the class exists on the runtime classpath (deployment jar includes custom classes).","Check for package/class renames in your CoreNLP version and update the name, or pin the older version.","Pre-test with Class.forName(name) in setup code to validate all class names used in rules at startup."],"exampleFix":"// before\n(CLASS) { type: \"CLASS\", value: \"CoreAnnotations$TokensAnnotation\" }\n// after\n(CLASS) { type: \"CLASS\", value: \"edu.stanford.nlp.ling.CoreAnnotations$TokensAnnotation\" }","handlingStrategy":"validation","validationCode":"static void validateClassName(String name) {\n  try { Class.forName(name); }\n  catch (ClassNotFoundException e) { throw new IllegalStateException(\"Class used in rule not on classpath: \" + name); }\n}","typeGuard":"static boolean resolvableClass(String name) {\n  try { Class.forName(name); return true; } catch (ClassNotFoundException e) { return false; }\n}","tryCatchPattern":"try { Value v = expr.evaluate(env, args); }\ncatch (RuntimeException ex) {\n  if (ex.getMessage().startsWith(\"Unknown class\")) {\n    log.error(\"Bad class name in rule: \" + ex.getMessage(), ex);\n  }\n  throw ex;\n}","preventionTips":["Use fully qualified names; $ for inner classes","Run a startup check resolving every class name referenced in rules","Keep custom annotation classes in the deployment jar; verify package names after CoreNLP upgrades"],"tags":["classnotfound","reflection","tokensregex","classpath"],"backgroundTag":"class-not-found","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"}