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 rareExtractor(...) spec instantiates a custom Extractor subclass reflectively, exactly like extractor(...) in ExtractorFrames. Any failure to load, construct, or cast the named class is wrapped in this RuntimeException with the class name.

Solutions

  1. Confirm the fully-qualified class name and that its jar is on the classpath when training
  2. Ensure the class extends Extractor and exposes a public no-argument constructor
  3. Inspect the nested 'caused by' exception for the root cause (ClassNotFound vs instantiation vs constructor error)
  4. Instantiate the class directly in a test to validate it before referencing it in config

Example fix

// before
String rareExtractors = "...,rareExtractor(tagging.RareFeat),..."; // fails to load
// after
String rareExtractors = "...,rareExtractor(com.example.tagging.RareFeat),..."; // FQN + on classpath

public class RareFeat extends Extractor {
  public RareFeat() { ... }
}
Defensive patterns

Strategy: try-catch

Validate before calling

try {
  Class<?> c = Class.forName(className);
  if (!Extractor.class.isAssignableFrom(c)) throw new IllegalArgumentException(className + " is not an Extractor");
  c.getDeclaredConstructor();
} catch (ClassNotFoundException | NoSuchMethodException e) {
  throw new IllegalStateException("Rare extractor class not loadable: " + className, e);
}

Try / catch

try {
  ExtractorFramesRare.getExtractorFramesRare(spec);
} catch (RuntimeException e) {
  if (e.getMessage() != null && e.getMessage().startsWith("Couldn't create POS tagger extractor class")) {
    // check e.getCause() for the reflection root cause
  } else { throw e; }
}

Prevention

When it happens

Trigger: Passing rareExtractor(com.example.MyRareExtractor) where the class is missing from the classpath, lacks a public no-arg constructor, does not extend Extractor, or throws from its constructor.

Common situations: Forgetting to add your custom extractor jar to the training classpath; wrong package name after a refactor; class compiled against an incompatible tagger version.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/tagger/maxent/ExtractorFramesRare.java:379

        }
      } else if (arg.startsWith("distsimconjunction(")) {
        String path = Extractor.getParenthesizedArg(arg, 1);
        int lWindow = Extractor.getParenthesizedNum(arg, 2);
        int rWindow = Extractor.getParenthesizedNum(arg, 3);
        extrs.add(new ExtractorDistsimConjunction(path, lWindow, rWindow));
      } else if (arg.equalsIgnoreCase("lctagfeatures")) {
        extrs.addAll(Arrays.asList(lcTagFeatures(ttags)));
      } else if (arg.equalsIgnoreCase("nonalphanumeric)")) {
        extrs.add(new ExtractorNonAlphanumeric());
      } else if (arg.equalsIgnoreCase("numeric)")) {
        extrs.add(new ExtractorNumeric());
      } else if (arg.startsWith("rareExtractor(")) {
        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);
        }
      }
    }

    return extrs.toArray(Extractor.EMPTY_EXTRACTOR_ARRAY);
  }


  /**
   * This provides the conjunction of various features as rare words features.
   *
   * @return An array of feature conjunctions
   */
  private static Extractor[] naacl2003Conjunctions() {
    Extractor[] newW = new Extractor[24];
    //add them manually ....
    newW[0] = new ExtractorsConjunction(cWordUppCase, cWordSuff1);
    newW[1] = new ExtractorsConjunction(cWordUppCase, cWordSuff2);

View on GitHub (pinned to 1b7edd19c4)