{"record":{"id":"f441a74dbf7e416c","repo":"stanfordnlp/CoreNLP","slug":"could-not-load-class-at-path","errorCode":null,"errorMessage":"Could not load class at path: ","messagePattern":"Could not load class at path: ","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/util/ArgumentParser.java","lineNumber":198,"sourceCode":"\n  @SuppressWarnings(\"rawtypes\")\n  private static Class filePathToClass(String cpEntry, String path) {\n    if (path.length() <= cpEntry.length()) {\n      throw new IllegalArgumentException(\"Illegal path: cp=\" + cpEntry\n          + \" path=\" + path);\n    }\n    if (path.charAt(cpEntry.length()) != '/') {\n      throw new IllegalArgumentException(\"Illegal path: cp=\" + cpEntry\n          + \" path=\" + path);\n    }\n    path = path.substring(cpEntry.length() + 1);\n    path = path.replaceAll(\"/\", \".\").substring(0, path.length() - 6);\n    try {\n      return Class.forName(path,\n          false,\n          ClassLoader.getSystemClassLoader());\n    } catch (ClassNotFoundException e) {\n      throw fail(\"Could not load class at path: \" + path);\n    } catch (NoClassDefFoundError ex) {\n      warn(\"Class at path \" + path + \" is unloadable\");\n      return null;\n    }\n  }\n\n  private static boolean isIgnored(String path) {\n    return Arrays.stream(IGNORED_JARS).anyMatch(path::endsWith);\n  }\n\n  private static Class<?>[] getVisibleClasses() {\n    //--Variables\n    List<Class<?>> classes = new ArrayList<>();\n    // (get classpath)\n    String pathSep = System.getProperty(\"path.separator\");\n    String[] cp = System.getProperties().getProperty(\"java.class.path\",\n        null).split(pathSep);\n    // --Fill Options","sourceCodeStart":180,"sourceCodeEnd":216,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/util/ArgumentParser.java#L180-L216","documentation":"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>\".","triggerScenarios":"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.)","commonSituations":"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).","solutions":["Use the fully-qualified class name (com.example.MyAnnotator), not a file path, in the argument","Ensure the jar/classes directory containing the class is on the system classpath (-cp), since this uses ClassLoader.getSystemClassLoader","Verify the exact class name/package with jar tf mylib.jar | grep MyAnnotator","Check for typos in the path-to-name conversion output shown in the error message"],"exampleFix":"// before\nprops.setProperty(\"annotators\", \"... , myAnnotator\");\nprops.setProperty(\"myAnnotator.class\", \"/build/classes/com/example/MyAnnotator.class\");\n// after\nprops.setProperty(\"annotators\", \"... , myAnnotator\");\nprops.setProperty(\"myAnnotator.class\", \"com.example.MyAnnotator\");\n// and run with: java -cp build/classes:stanford-corenlp.jar ...","handlingStrategy":"validation","validationCode":"// Java: verify the class is loadable before passing it to ArgumentParser\nstatic void requireClass(String fqn) {\n  try {\n    Class.forName(fqn, false, ClassLoader.getSystemClassLoader());\n  } catch (ClassNotFoundException e) {\n    throw new IllegalArgumentException(\"Class not on system classpath: \" + fqn, e);\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  Class<?> c = argParser.clazz(\"myAnnotator.class\");\n} catch (ArgumentParser.ParseException e) {\n  throw new IllegalStateException(\"Check -cp and the FQN in the argument: \" + e.getMessage(), e);\n}","preventionTips":["Pass fully-qualified class names, never .class file paths","Verify jar/class dirs are on the system classpath with -cp or CLASSPATH","Use `jar tf` or `find` to confirm the exact package/class name","Remember this loader is the system classloader — classes in webapp/plugin classloaders won't resolve"],"tags":["classpath","reflection","argument-parsing"],"backgroundTag":"class-not-found","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"}