{"record":{"id":"be701a40e44ed272","repo":"stanfordnlp/CoreNLP","slug":"someone-didn-t-add-a-handler-for-a-new-doctype","errorCode":null,"errorMessage":"Someone didn't add a handler for a new docType.","messagePattern":"Someone didn't add a handler for a new docType\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/process/DocumentPreprocessor.java","lineNumber":231,"sourceCode":"\n\n  /**\n   * Returns sentences until the document is exhausted. Calls close() if the end of the document\n   * is reached. Otherwise, the user is required to close the stream.\n   *\n   * @return An Iterator over sentences (each a List of word tokens).\n   * Although the type is given as {@code List<HasWord>}, in practice you get a List of CoreLabel,\n   * and you can cast down to that. (Someday we might manage to fix the generic typing....)\n   */\n  @Override\n  public Iterator<List<HasWord>> iterator() {\n    // Add new document types here\n    if (docType == DocType.Plain) {\n      return new PlainTextIterator();\n    } else if (docType == DocType.XML) {\n      return new XMLIterator();\n    } else {\n      throw new IllegalStateException(\"Someone didn't add a handler for a new docType.\");\n    }\n  }\n\n\n  private class PlainTextIterator implements Iterator<List<HasWord>> {\n\n    private final Tokenizer<? extends HasWord> tokenizer;\n    private final Set<String> sentDelims;\n    private final Set<String> delimFollowers;\n    private final Function<String, String[]> splitTag;\n    private List<HasWord> nextSent; // = null;\n    private final List<HasWord> nextSentCarryover = Generics.newArrayList();\n\n    public PlainTextIterator() {\n      // Establish how to find sentence boundaries\n      boolean eolIsSignificant = false;\n      sentDelims = Generics.newHashSet();\n      if (sentenceDelimiter == null) {","sourceCodeStart":213,"sourceCodeEnd":249,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/process/DocumentPreprocessor.java#L213-L249","documentation":"DocumentPreprocessor.iterator() dispatches on the DocType enum; only Plain and XML have implemented iterators. If docType holds any other value, the library throws this IllegalStateException because a new DocType was added without a corresponding iterator handler. In normal use this means the DocType passed to the constructor is not supported by this code path.","triggerScenarios":"Constructing a DocumentPreprocessor with a DocType other than Plain or XML (e.g. a custom/newer DocType constant) and then iterating via iterator(), tokens(), or a for-each over the preprocessor.","commonSituations":"Using a DocumentPreprocessor subclass or an upgraded enum from a newer CoreNLP version with an older iterator implementation; copy-pasted construction code setting an exotic DocType; reflection-based instantiation choosing the wrong enum constant.","solutions":["Use DocType.Plain for regular text or DocType.XML for XML documents","Check for a version mismatch between library jars and switch to a consistent CoreNLP version","If you added a custom DocType, implement and return a matching Iterator in iterator()'s dispatch chain","Validate the DocType right after construction (fail early) rather than at iteration time"],"exampleFix":"// before\nDocumentPreprocessor dp = new DocumentPreprocessor(reader, DocType.Media);\n// after\nDocumentPreprocessor dp = new DocumentPreprocessor(reader, DocType.Plain); // supported type","handlingStrategy":"validation","validationCode":"if (docType != DocType.Plain && docType != DocType.XML) {\n  throw new IllegalArgumentException(\"Unsupported DocType for DocumentPreprocessor: \" + docType);\n}","typeGuard":null,"tryCatchPattern":"try (Iterable<List<HasWord>> sents = () -> dp.iterator()) {\n  // consume sentences\n} catch (IllegalStateException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"didn't add a handler\")) {\n    throw new UnsupportedDocTypeException(docType, e);\n  }\n  throw e;\n}","preventionTips":["Restrict DocType usage to Plain and XML in your code","Pin all CoreNLP jars to one version to avoid enum/implementation mismatches","Assert the DocType immediately after construction rather than at iteration time"],"tags":["enum","dispatch","unsupported-operation","illegal-state","version-mismatch"],"backgroundTag":"unsupported-enum-value","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}