stanfordnlp/CoreNLP · error · RuntimeException

Could not load class at path:

Error message

Could not load class at path: 

What it means

ArgumentParser.filePathToClass converts a class file path (e.g., com/foo/Bar.class) to a class name and loads it with Class.forName on the system classloader with initialize=false. If the class isn't on the system classpath, it throws a fail() exception with "Could not load class at path: <fqn>".

Solutions

  1. Use the fully-qualified class name (com.example.MyAnnotator), not a file path, in the argument
  2. Ensure the jar/classes directory containing the class is on the system classpath (-cp), since this uses ClassLoader.getSystemClassLoader
  3. Verify the exact class name/package with jar tf mylib.jar | grep MyAnnotator
  4. Check for typos in the path-to-name conversion output shown in the error message

Example fix

// before
props.setProperty("annotators", "... , myAnnotator");
props.setProperty("myAnnotator.class", "/build/classes/com/example/MyAnnotator.class");
// after
props.setProperty("annotators", "... , myAnnotator");
props.setProperty("myAnnotator.class", "com.example.MyAnnotator");
// and run with: java -cp build/classes:stanford-corenlp.jar ...
Defensive patterns

Strategy: validation

Validate before calling

// Java: verify the class is loadable before passing it to ArgumentParser
static void requireClass(String fqn) {
  try {
    Class.forName(fqn, false, ClassLoader.getSystemClassLoader());
  } catch (ClassNotFoundException e) {
    throw new IllegalArgumentException("Class not on system classpath: " + fqn, e);
  }
}

Try / catch

try {
  Class<?> c = argParser.clazz("myAnnotator.class");
} catch (ArgumentParser.ParseException e) {
  throw new IllegalStateException("Check -cp and the FQN in the argument: " + e.getMessage(), e);
}

Prevention

When it happens

Trigger: Using ArgumentParser options that accept a class path (called by clazz(...)) where the given path doesn't map to a class loadable by ClassLoader.getSystemClassLoader — wrong path, missing class file, or class outside the classpath. (A NoClassDefFoundError instead yields a warning and null.)

Common situations: Passing a file path or misspelled FQN in pipeline properties (e.g., classifier=.../MyAnnotator.class) instead of a class name; jar not on the classpath; class compiled for a different Java version (though that usually surfaces as NoClassDefFoundError).

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/util/ArgumentParser.java:198

  @SuppressWarnings("rawtypes")
  private static Class filePathToClass(String cpEntry, String path) {
    if (path.length() <= cpEntry.length()) {
      throw new IllegalArgumentException("Illegal path: cp=" + cpEntry
          + " path=" + path);
    }
    if (path.charAt(cpEntry.length()) != '/') {
      throw new IllegalArgumentException("Illegal path: cp=" + cpEntry
          + " path=" + path);
    }
    path = path.substring(cpEntry.length() + 1);
    path = path.replaceAll("/", ".").substring(0, path.length() - 6);
    try {
      return Class.forName(path,
          false,
          ClassLoader.getSystemClassLoader());
    } catch (ClassNotFoundException e) {
      throw fail("Could not load class at path: " + path);
    } catch (NoClassDefFoundError ex) {
      warn("Class at path " + path + " is unloadable");
      return null;
    }
  }

  private static boolean isIgnored(String path) {
    return Arrays.stream(IGNORED_JARS).anyMatch(path::endsWith);
  }

  private static Class<?>[] getVisibleClasses() {
    //--Variables
    List<Class<?>> classes = new ArrayList<>();
    // (get classpath)
    String pathSep = System.getProperty("path.separator");
    String[] cp = System.getProperties().getProperty("java.class.path",
        null).split(pathSep);
    // --Fill Options

View on GitHub (pinned to 1b7edd19c4)