{"record":{"id":"1be871f064c96374","repo":"stanfordnlp/CoreNLP","slug":"error-loading-flags-readerandwriter-s","errorCode":null,"errorMessage":"Error loading flags.readerAndWriter: '%s'","messagePattern":"Error loading flags\\.readerAndWriter: '(.+?)'","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/ie/AbstractSequenceClassifier.java","lineNumber":241,"sourceCode":"\n  public Set<String> getKnownLCWords() {\n    return knownLCWords;\n  }\n\n  /**\n   * Makes a DocumentReaderAndWriter based on the flags the CRFClassifier\n   * was constructed with.  Will create an instance of the class specified in\n   * the property flags.readerAndWriter and\n   * initialize it with the CRFClassifier's flags.\n   *\n   * @return The appropriate ReaderAndWriter for training/testing this classifier\n   */\n  public DocumentReaderAndWriter<IN> makeReaderAndWriter() {\n    DocumentReaderAndWriter<IN> readerAndWriter;\n    try {\n      readerAndWriter = ReflectionLoading.loadByReflection(flags.readerAndWriter);\n    } catch (Exception e) {\n      throw new RuntimeException(String.format(\"Error loading flags.readerAndWriter: '%s'\", flags.readerAndWriter), e);\n    }\n    readerAndWriter.init(flags);\n    return readerAndWriter;\n  }\n\n  /**\n   * Makes a DocumentReaderAndWriter based on\n   * flags.plainTextReaderAndWriter.  Useful for reading in\n   * untokenized text documents or reading plain text from the command\n   * line.  An example of a way to use this would be to return a\n   * edu.stanford.nlp.wordseg.Sighan2005DocumentReaderAndWriter for\n   * the Chinese Segmenter.\n   */\n  public static <INN extends CoreMap> DocumentReaderAndWriter<INN> makePlainTextReaderAndWriter(SeqClassifierFlags flags) {\n    String readerClassName = flags.plainTextDocumentReaderAndWriter;\n    // We set this default here if needed because there may be models\n    // which don't have the reader flag set\n    if (readerClassName == null) {","sourceCodeStart":223,"sourceCodeEnd":259,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ie/AbstractSequenceClassifier.java#L223-L259","documentation":"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`.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before (in props)\nreaderAndWriter = edu.stanford.nlp.sequences.ColumnDocumentReaderAndWritter\n// after\nreaderAndWriter = edu.stanford.nlp.sequences.ColumnDocumentReaderAndWriter","handlingStrategy":"try-catch","validationCode":"try {\n  Class.forName(flags.readerAndWriter);\n} catch (ClassNotFoundException e) {\n  throw new IllegalStateException(\"readerAndWriter class not on classpath: \" + flags.readerAndWriter);\n}","typeGuard":null,"tryCatchPattern":"try { rw = classifier.makeReaderAndWriter(); }\ncatch (RuntimeException e) { log.error(\"Bad flags.readerAndWriter: {}\", e.getMessage(), e.getCause()); throw e; }","preventionTips":["Use fully-qualified class names copied from the Javadoc","Add a startup smoke test that instantiates the reader","Keep training and serving classpaths aligned"],"tags":["reflection","classpath","config"],"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"}