stanfordnlp/CoreNLP · error · RuntimeException
Error loading flags.plainTextDocumentReaderAndWriter
Error message
Error loading flags.plainTextDocumentReaderAndWriter: '%s'
What it means
makePlainTextReaderAndWriter loads the plain-text DocumentReaderAndWriter class by reflection (defaulting to SeqClassifierFlags.DEFAULT_PLAIN_TEXT_READER when flags.plainTextDocumentReaderAndWriter is unset) and wraps any load failure in a RuntimeException naming the flag. Same failure modes as the general readerAndWriter loading.
Solutions
- Inspect the wrapped cause exception for the real load error
- Unset the flag to fall back to SeqClassifierFlags.DEFAULT_PLAIN_TEXT_READER, or set it to a valid class like edu.stanford.nlp.objectbank.ObjectBank$LineSplittable... / PlainTextDocumentReaderAndWriter
- Ensure the class is on the runtime classpath
- Verify the class implements DocumentReaderAndWriter and has a public no-arg constructor
Example fix
// before plainTextDocumentReaderAndWriter = edu.stanford.nlp.PlarinTextDocumentReaderAndWriter // after plainTextDocumentReaderAndWriter = edu.stanford.nlp.ie.Platinum... -> use correct FQCN, e.g. remove the line to use the default
Defensive patterns
Strategy: try-catch
Validate before calling
String cls = flags.plainTextDocumentReaderAndWriter != null ? flags.plainTextDocumentReaderAndWriter : SeqClassifierFlags.DEFAULT_PLAIN_TEXT_READER;
try { Class.forName(cls); } catch (ClassNotFoundException e) { throw new IllegalStateException("bad plainText reader class: " + cls); } Try / catch
try { rw = classifier.makePlainTextReaderAndWriter(); }
catch (RuntimeException e) { log.error("Bad plainTextDocumentReaderAndWriter: {}", e.getCause(), e); throw e; } Prevention
- Omit the flag to use the documented default reader
- Validate class names at config load time
- Keep custom readers in the deployed jar
When it happens
Trigger: Calling makePlainTextReaderAndWriter() when flags.plainTextDocumentReaderAndWriter names a nonexistent class, a class without a no-arg constructor, or one that fails during reflective instantiation.
Common situations: Typo in the plainTextDocumentReaderAndWriter property; custom reader class not packaged in the deployed jar; copy-pasted fully-qualified class name with a mistake.
Related errors
- Error loading flags.readerAndWriter
- 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/f8a98b0b9ed8c0ab.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/ie/AbstractSequenceClassifier.java:266
* 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) {
readerClassName = SeqClassifierFlags.DEFAULT_PLAIN_TEXT_READER;
}
DocumentReaderAndWriter<INN> readerAndWriter;
try {
readerAndWriter = ReflectionLoading.loadByReflection(readerClassName);
} catch (Exception e) {
throw new RuntimeException(String.format("Error loading flags.plainTextDocumentReaderAndWriter: '%s'", flags.plainTextDocumentReaderAndWriter), e);
}
readerAndWriter.init(flags);
return readerAndWriter;
}
public DocumentReaderAndWriter<IN> makePlainTextReaderAndWriter() {
return makePlainTextReaderAndWriter(flags);
}
/**
* Returns the background class for the classifier.
*
* @return The background class name
*/
public String backgroundSymbol() {
return flags.backgroundSymbol;
}
View on GitHub (pinned to 1b7edd19c4)