{"record":{"id":"e7180647010ffcc9","repo":"stanfordnlp/CoreNLP","slug":"illegal-path-cp","errorCode":null,"errorMessage":"Illegal path: cp=","messagePattern":"Illegal path: cp=","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/util/ArgumentParser.java","lineNumber":184,"sourceCode":"      if (!accessState) {\n        f.setAccessible(false);\n      }\n    } catch (IllegalArgumentException e) {\n      err(e);\n      runtimeException(\"Cannot assign option field: \" + f.getDeclaringClass().getCanonicalName() + '.' + f.getName() + \" value: \" + value + \" cause: \" + e.getMessage());\n    } catch (IllegalAccessException e) {\n      err(e);\n      runtimeException(\"Cannot access option field: \" + f.getDeclaringClass().getCanonicalName() + '.' + f.getName());\n    } catch (Exception e) {\n      err(e);\n      runtimeException(\"Cannot assign option field: \" + f.getDeclaringClass().getCanonicalName() + '.' + f.getName() + \" value: \" + value + \" cause: \" + e.getMessage());\n    }\n  }\n\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    }","sourceCodeStart":166,"sourceCodeEnd":202,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/util/ArgumentParser.java#L166-L202","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nclazz(filePathToClass(cpEntry, path));\n// after: caller guards\nif (path.length() <= cpEntry.length() || !path.startsWith(cpEntry)) {\n  return; // skip invalid cp mapping\n}","handlingStrategy":"validation","validationCode":"if (path.length() <= cpEntry.length() || !path.startsWith(cpEntry)) { skip(); }","typeGuard":"boolean isValidCpPath(String cpEntry, String path) { return path != null && path.length() > cpEntry.length(); }","tryCatchPattern":"try { return filePathToClass(cpEntry, path); } catch (IllegalArgumentException e) { log.warn(\"Bad cp mapping: \" + e.getMessage()); return null; }","preventionTips":["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."],"tags":["classpath","argument-parser","reflection","illegal-argument"],"backgroundTag":"invalid-argument-value","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"}