stanfordnlp/CoreNLP · error · RuntimeException

Couldn't create POS tagger extractor class

Error message

Couldn't create POS tagger extractor class ${className}

What it means

The extractor(...) spec instantiates a user-supplied Extractor subclass reflectively via Class.forName(...).newInstance(). If the class cannot be found, is not an Extractor, has no no-arg constructor, or its constructor throws, the exception is wrapped in this RuntimeException naming the class.

Solutions

  1. Verify the fully-qualified class name is spelled correctly and the class is on the classpath at runtime
  2. Ensure the class extends edu.stanford.nlp.tagger.maxent.Extractor and has a public no-argument constructor
  3. Read the 'caused by' exception in the stack trace to distinguish ClassNotFoundException from InstantiationException or constructor failures
  4. Test instantiating the class with a plain 'new MyExtractor()' in a unit test before wiring it into the tagger config

Example fix

// before
String extractors = "...,extractor(MyExtractor),..."; // not found
// after (fully qualified, on classpath, public no-arg ctor)
String extractors = "...,extractor(com.example.tagging.MyExtractor),...";

// class must look like:
public class MyExtractor extends Extractor {
  public MyExtractor() { super(...); }
}
Defensive patterns

Strategy: try-catch

Validate before calling

try {
  Class<?> c = Class.forName(className);
  if (!Extractor.class.isAssignableFrom(c)) throw new IllegalArgumentException(className + " does not extend Extractor");
  c.getDeclaredConstructor(); // fails fast if no no-arg ctor
} catch (ClassNotFoundException | NoSuchMethodException e) {
  throw new IllegalStateException("Extractor class not loadable: " + className, e);
}

Try / catch

try {
  ExtractorFrames.getExtractorFrames(spec);
} catch (RuntimeException e) {
  if (e.getMessage() != null && e.getMessage().startsWith("Couldn't create POS tagger extractor class")) {
    // inspect e.getCause(): ClassNotFoundException vs ctor failure
  } else { throw e; }
}

Prevention

When it happens

Trigger: Passing extractor(com.example.MyExtractor) where the class is not on the classpath, lacks a public no-argument constructor, does not extend Extractor, or throws in its constructor.

Common situations: Custom extractor jar missing from the runtime classpath; typo in the fully-qualified class name; extractor class written for a different CoreNLP version with an incompatible Extractor signature; abstract or constructor-failing class.

Related errors


AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10). Data as JSON: /api/errors/dbf672342e385612. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/tagger/maxent/ExtractorFrames.java:280

        int lWindow = Extractor.getParenthesizedNum(arg, 1);
        int rWindow = Extractor.getParenthesizedNum(arg, 2);
        for (int i = lWindow; i <= rWindow; i++) {
          extrs.add(new ExtractorWordShapeClassifier(i, "chris4"));
        }
      } else if (arg.startsWith("allunicodeshapeconjunction(")) {
        int lWindow = Extractor.getParenthesizedNum(arg, 1);
        int rWindow = Extractor.getParenthesizedNum(arg, 2);
        extrs.add(new ExtractorWordShapeConjunction(lWindow, rWindow, "chris4"));
      } else if (arg.equalsIgnoreCase("spanishauxiliaries")) {
        extrs.add(new ExtractorSpanishAuxiliaryTag());
        extrs.add(new ExtractorSpanishSemiauxiliaryTag());
      } else if (arg.startsWith("extractor(")) {
        String className = Extractor.getParenthesizedArg(arg, 1);
        try {
          Extractor e = (Extractor) Class.forName(className).getDeclaredConstructor().newInstance();
          extrs.add(e);
        } catch (Exception e) {
          throw new RuntimeException("Couldn't create POS tagger extractor class " + className, e);
        }
      } else if (arg.equalsIgnoreCase("naacl2003unknowns") ||
                 arg.equalsIgnoreCase("lnaacl2003unknowns") ||
                 arg.equalsIgnoreCase("caselessnaacl2003unknowns") ||
                 arg.equalsIgnoreCase("naacl2003conjunctions") ||
                 arg.equalsIgnoreCase("frenchunknowns") ||
                 arg.equalsIgnoreCase("spanishunknowns") ||
                 arg.startsWith("wordshapes(") ||
                 arg.startsWith("wordshapeconjunction(") ||
                 arg.equalsIgnoreCase("motleyUnknown") ||
                 arg.startsWith("suffix(") ||
                 arg.startsWith("prefix(") ||
                 arg.startsWith("prefixsuffix") ||
                 arg.startsWith("capitalizationsuffix(") ||
                 arg.startsWith("distsim(") ||
                 arg.startsWith("distsimconjunction(") ||
                 arg.equalsIgnoreCase("lctagfeatures") ||
                 arg.startsWith("rareExtractor(") ||

View on GitHub (pinned to 1b7edd19c4)