stanfordnlp/CoreNLP · error · RuntimeException

Loading: failed with

Error message

Loading: ${postProcessorClass} failed with: ${e.getMessage()}

What it means

TokenizerAnnotator loads the 'tokenize.postprocessor' class via reflection (ReflectionLoading.loadByReflection). If the class cannot be found, instantiated, or its constructor throws, the wrapping catch rethrows it as a RuntimeException naming the class and the underlying message.

Solutions

  1. Verify the fully-qualified class name and that the class is on the runtime classpath.
  2. Ensure the class implements CoreLabelProcessor and has an accessible no-argument constructor.
  3. Instantiate the class directly in a test to see the real underlying exception.
  4. Remove tokenize.postprocessor if a post-processor is not needed.

Example fix

// before
props.setProperty("tokenize.postprocessor", "my.pkg.MyProcessor");
// after (class verified on classpath, implements CoreLabelProcessor, no-arg ctor)
props.setProperty("tokenize.postprocessor", "com.example.nlp.MyTokenPostProcessor");
Defensive patterns

Strategy: try-catch

Validate before calling

String cls = props.getProperty("tokenize.postprocessor");
if (cls != null && !cls.isEmpty()) {
  try { Class.forName(cls); } catch (ClassNotFoundException e) { throw new IllegalStateException("tokenize.postprocessor not on classpath: " + cls); }
}

Type guard

boolean classExists(String name) { try { Class.forName(name); return true; } catch (Throwable t) { return false; } }

Try / catch

try { new TokenizerAnnotator(props); } catch (RuntimeException e) { log.error("Postprocessor load failed: " + e.getMessage()); throw e; }

Prevention

When it happens

Trigger: Setting tokenize.postprocessor to a class name that is misspelled, not on the classpath, lacks a no-arg constructor, or whose constructor throws a RuntimeException during TokenizerAnnotator construction.

Common situations: Typo in fully-qualified class name; missing jar on classpath; custom CoreLabelProcessor whose constructor depends on unavailable resources; running under a different package layout after refactor.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/pipeline/TokenizerAnnotator.java:239

                                   LanguageInfo.getLanguageFromString(props.getProperty("tokenize.language")));
      }
    } else if (props.getProperty(STANFORD_CDC_TOKENIZE + ".model", null) != null) {
      cdcAnnotator = new StatTokSentAnnotator(props);
      segmenterAnnotator = null;
    } else {
      segmenterAnnotator = null;
      cdcAnnotator = null;
    }

    // load any custom token post processing
    String postProcessorClass = props.getProperty("tokenize.postProcessor", "");
    List<CoreLabelProcessor> processors = new ArrayList<>();
    try {
      if (!postProcessorClass.equals("")) {
        processors.add(ReflectionLoading.loadByReflection(postProcessorClass));
      }
    } catch (RuntimeException e) {
      throw new RuntimeException("Loading: "+postProcessorClass+" failed with: "+e.getMessage());
    }
    if (PropertiesUtils.getBool(props, "tokenize.codepoint")) {
      processors.add(new CodepointCoreLabelProcessor());
    }
    postProcessors = Collections.unmodifiableList(processors);

    VERBOSE = PropertiesUtils.getBool(props, "tokenize.verbose", verbose);
    TokenizerType type = TokenizerType.getTokenizerType(props);
    factory = initFactory(type, props, options);
    if (VERBOSE) {
      log.info("Initialized tokenizer factory: " + factory);
    }

    if (PropertiesUtils.getBool(props, STANFORD_TOKENIZE + "." + STANFORD_CLEAN_XML)) {
      this.cleanxmlAnnotator = new CleanXmlAnnotator(props);
    } else {
      this.cleanxmlAnnotator = null;
    }

View on GitHub (pinned to 1b7edd19c4)