stanfordnlp/CoreNLP · error · RuntimeException
Error loading flags.readerAndWriter
Error message
Error loading flags.readerAndWriter: '%s'
What it means
AbstractSequenceClassifier.makeReaderAndWriter loads the DocumentReaderAndWriter class named by flags.readerAndWriter via reflection; any failure (class missing, no default constructor, init error) is wrapped in a RuntimeException naming the flag value. The root cause is the wrapped exception `e`.
Solutions
- Check the cause (`e`) of the RuntimeException for ClassNotFoundException or InstantiationException details
- Verify flags.readerAndWriter matches an existing DocumentReaderAndWriter implementation (e.g. edu.stanford.nlp.sequences.ColumnDocumentReaderAndWriter)
- Ensure the class is on the classpath (add your jar or the module containing it)
- Confirm the class has a public no-argument constructor
Example fix
// before (in props) readerAndWriter = edu.stanford.nlp.sequences.ColumnDocumentReaderAndWritter // after readerAndWriter = edu.stanford.nlp.sequences.ColumnDocumentReaderAndWriter
Defensive patterns
Strategy: try-catch
Validate before calling
try {
Class.forName(flags.readerAndWriter);
} catch (ClassNotFoundException e) {
throw new IllegalStateException("readerAndWriter class not on classpath: " + flags.readerAndWriter);
} Try / catch
try { rw = classifier.makeReaderAndWriter(); }
catch (RuntimeException e) { log.error("Bad flags.readerAndWriter: {}", e.getMessage(), e.getCause()); throw e; } Prevention
- Use fully-qualified class names copied from the Javadoc
- Add a startup smoke test that instantiates the reader
- Keep training and serving classpaths aligned
When it happens
Trigger: Setting flags.readerAndWriter to a class name that does not exist, is not on the classpath, lacks a no-arg constructor, is not a DocumentReaderAndWriter, or whose constructor throws.
Common situations: Typo in the readerAndWriter property of a classifier config/serialized flag file; using a custom reader class not included in the jar; classpath differences between training and inference environments.
Related errors
- Error loading flags.plainTextDocumentReaderAndWriter
- Unknown class
- Couldn't instantiate CategoryMergingGrammarCompactor.
- Loading: failed with
- Could not load tokenizer factory
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/1be871f064c96374.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/ie/AbstractSequenceClassifier.java:241
public Set<String> getKnownLCWords() {
return knownLCWords;
}
/**
* Makes a DocumentReaderAndWriter based on the flags the CRFClassifier
* was constructed with. Will create an instance of the class specified in
* the property flags.readerAndWriter and
* initialize it with the CRFClassifier's flags.
*
* @return The appropriate ReaderAndWriter for training/testing this classifier
*/
public DocumentReaderAndWriter<IN> makeReaderAndWriter() {
DocumentReaderAndWriter<IN> readerAndWriter;
try {
readerAndWriter = ReflectionLoading.loadByReflection(flags.readerAndWriter);
} catch (Exception e) {
throw new RuntimeException(String.format("Error loading flags.readerAndWriter: '%s'", flags.readerAndWriter), e);
}
readerAndWriter.init(flags);
return readerAndWriter;
}
/**
* Makes a DocumentReaderAndWriter based on
* flags.plainTextReaderAndWriter. Useful for reading in
* untokenized text documents or reading plain text from the command
* line. An example of a way to use this would be to return a
* edu.stanford.nlp.wordseg.Sighan2005DocumentReaderAndWriter for
* the Chinese Segmenter.
*/
public static <INN extends CoreMap> DocumentReaderAndWriter<INN> makePlainTextReaderAndWriter(SeqClassifierFlags flags) {
String readerClassName = flags.plainTextDocumentReaderAndWriter;
// We set this default here if needed because there may be models
// which don't have the reader flag set
if (readerClassName == null) {View on GitHub (pinned to 1b7edd19c4)