stanfordnlp/CoreNLP · error · ReflectionLoadingException
Error creating " + className
Error message
Error creating " + className
What it means
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.
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
Example fix
// before
MyTokenizer t = ReflectionLoading.loadByReflection("edu.stanford.nlp.process.MyTokenzier"); // typo
// after
MyTokenizer t = ReflectionLoading.loadByReflection("edu.stanford.nlp.process.MyTokenizer"); Defensive patterns
Strategy: try-catch
Validate before calling
String name = "edu.stanford.nlp.process.MyTokenizer";
try { Class.forName(name); } catch (ClassNotFoundException e) { /* fix name/classpath before calling */ } Try / catch
try {
T obj = ReflectionLoading.loadByReflection(className, args);
} catch (ReflectionLoadingException e) {
log.error("Cannot create " + className + ": " + e.getCause());
throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Class at path
- Error getting field value for
- Cannot get field from
- Loading: failed with
- Couldn't create POS tagger extractor class
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/1a732b8cdd245e63.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/util/ReflectionLoading.java:38
* <br>
* {@code String s = ReflectionLoading.loadByReflection("java.lang.String", "foo"); }
* <br>
* {@code String s = ReflectionLoading.loadByReflection("java.lang.String"); }
* <br>
* Note that this uses generics for convenience, but this does
* nothing for compile-time error checking. You can do:
* <br>
* {@code Integer i = ReflectionLoading.loadByReflection("java.lang.String"); }
* <br>
* and it will compile just fine, but will result in a ClassCastException.
*/
@SuppressWarnings("unchecked")
public static <T> T loadByReflection(String className,
Object ... arguments) {
try{
return (T) new MetaClass(className).createInstance(arguments);
} catch (Exception e) {
throw new ReflectionLoadingException("Error creating " + className, e);
}
}
/**
* This class encapsulates all of the exceptions that can be thrown
* when loading something by reflection.
*/
public static class ReflectionLoadingException extends RuntimeException {
private static final long serialVersionUID = -3324911744277952585L;
public ReflectionLoadingException(String message, Throwable reason) {
super(message, reason);
}
}
View on GitHub (pinned to 1b7edd19c4)