stanfordnlp/CoreNLP · error · IllegalArgumentException
Illegal path: cp=
Error message
Illegal path: cp=
What it means
ArgumentParser.filePathToClass converts a class file path back into a fully-qualified class name by stripping the classpath entry prefix. This IllegalArgumentException is thrown when the path is not longer than the classpath entry, so nothing could remain after stripping. It indicates the path does not actually reside under the given classpath entry.
Solutions
- Verify the classpath entry is the correct parent directory of the path (no trailing slash vs slash mismatch).
- Ensure path is an absolute path under cpEntry before conversion.
- Skip non-class entries or entries whose paths don't start with the cp entry when scanning.
- Debug by printing cpEntry and path; the message includes both.
Example fix
// before
clazz(filePathToClass(cpEntry, path));
// after: caller guards
if (path.length() <= cpEntry.length() || !path.startsWith(cpEntry)) {
return; // skip invalid cp mapping
} Defensive patterns
Strategy: validation
Validate before calling
if (path.length() <= cpEntry.length() || !path.startsWith(cpEntry)) { skip(); } Type guard
boolean isValidCpPath(String cpEntry, String path) { return path != null && path.length() > cpEntry.length(); } Try / catch
try { return filePathToClass(cpEntry, path); } catch (IllegalArgumentException e) { log.warn("Bad cp mapping: " + e.getMessage()); return null; } Prevention
- Keep classpath entries normalized (consistent absolute paths, matching separators).
- Only pass paths that are strictly under the classpath entry.
- Skip directory entries that cannot contain the scanned path.
When it happens
Trigger: filePathToClass(cpEntry, path) called (via clazz) with a path whose length is <= cpEntry.length(), e.g. path equals the classpath entry itself or is shorter — a file path found on the classpath that is not under the cp directory entry.
Common situations: Scanning a classpath where a directory entry was recorded wrong (trailing-slash mismatch making cpEntry as long as the path); a JAR-file path passed with a directory cp entry; classpath built from stale or malformed entries.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Class at path
- Class is in classpath multiple times
- Could not create l1 minimizer! Reverting to l2.
- Could not load class at path:
- Could not load class in jar:
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/e7180647010ffcc9.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/util/ArgumentParser.java:184
if (!accessState) {
f.setAccessible(false);
}
} catch (IllegalArgumentException e) {
err(e);
runtimeException("Cannot assign option field: " + f.getDeclaringClass().getCanonicalName() + '.' + f.getName() + " value: " + value + " cause: " + e.getMessage());
} catch (IllegalAccessException e) {
err(e);
runtimeException("Cannot access option field: " + f.getDeclaringClass().getCanonicalName() + '.' + f.getName());
} catch (Exception e) {
err(e);
runtimeException("Cannot assign option field: " + f.getDeclaringClass().getCanonicalName() + '.' + f.getName() + " value: " + value + " cause: " + e.getMessage());
}
}
@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;
}View on GitHub (pinned to 1b7edd19c4)