{"record":{"id":"1a732b8cdd245e63","repo":"stanfordnlp/CoreNLP","slug":"error-creating-classname","errorCode":null,"errorMessage":"Error creating \" + className","messagePattern":"Error creating \" \\+ className","errorType":"exception","errorClass":"ReflectionLoadingException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/util/ReflectionLoading.java","lineNumber":38,"sourceCode":"   * <br>\n   *  {@code String s = ReflectionLoading.loadByReflection(\"java.lang.String\", \"foo\"); }\n   * <br>\n   *  {@code String s = ReflectionLoading.loadByReflection(\"java.lang.String\"); }\n   * <br>\n   * Note that this uses generics for convenience, but this does\n   * nothing for compile-time error checking.  You can do:\n   * <br>\n   *  {@code Integer i = ReflectionLoading.loadByReflection(\"java.lang.String\"); }\n   * <br>\n   * and it will compile just fine, but will result in a ClassCastException.\n   */\n  @SuppressWarnings(\"unchecked\")\n  public static <T> T loadByReflection(String className,\n                                       Object ... arguments) {\n    try{\n      return (T) new MetaClass(className).createInstance(arguments);\n    } catch (Exception e) {\n      throw new ReflectionLoadingException(\"Error creating \" + className, e);\n    }\n  }\n\n  /**\n   * This class encapsulates all of the exceptions that can be thrown\n   * when loading something by reflection.\n   */\n  public static class ReflectionLoadingException extends RuntimeException {\n\n    private static final long serialVersionUID = -3324911744277952585L;\n\n\n    public ReflectionLoadingException(String message, Throwable reason) {\n      super(message, reason);\n    }\n\n  }\n","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/util/ReflectionLoading.java#L20-L56","documentation":"ReflectionLoading.loadByReflection instantiates a class by name via MetaClass and wraps any failure (class not found, constructor mismatch, exception thrown in constructor) into a ReflectionLoadingException with the message 'Error creating <className>'. It is a uniform wrapper for reflection-based object creation used throughout Stanford NLP.","triggerScenarios":"Calling ReflectionLoading.loadByReflection(\"com.example.Foo\", args...) when the class name is misspelled, the class is not on the classpath, no matching constructor exists for the arguments, or the constructor itself throws.","commonSituations":"Configuring a custom tokenizer, parser, or annotator class via a string property with a typo or wrong package; dependency jar missing at runtime so the class can't load; constructor signature changed between versions while a config file still lists old arguments.","solutions":["Verify the fully-qualified class name in your config and that its jar is on the classpath","Check the class has a public constructor matching the arguments you pass","Inspect the cause (getCause()) of the ReflectionLoadingException for the underlying ClassNotFoundException or constructor error"],"exampleFix":"// before\nMyTokenizer t = ReflectionLoading.loadByReflection(\"edu.stanford.nlp.process.MyTokenzier\"); // typo\n// after\nMyTokenizer t = ReflectionLoading.loadByReflection(\"edu.stanford.nlp.process.MyTokenizer\");","handlingStrategy":"try-catch","validationCode":"String name = \"edu.stanford.nlp.process.MyTokenizer\";\ntry { Class.forName(name); } catch (ClassNotFoundException e) { /* fix name/classpath before calling */ }","typeGuard":null,"tryCatchPattern":"try {\n  T obj = ReflectionLoading.loadByReflection(className, args);\n} catch (ReflectionLoadingException e) {\n  log.error(\"Cannot create \" + className + \": \" + e.getCause());\n  throw e;\n}","preventionTips":["Store fully-qualified class names in config constants, not inline strings","Ensure the jar containing the class is on the runtime classpath","Keep constructor signatures in sync with the argument lists in config files"],"tags":["java","reflection","class-loading"],"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"}