{"record":{"id":"036d6578c2e9fab2","repo":"openjdk/jdk","slug":"system-class-loader-does-not-define-the-appendtocl","errorCode":null,"errorMessage":"System class loader does not define the appendToClassPathForInstrumentation method\\n","messagePattern":"System class loader does not define the appendToClassPathForInstrumentation method\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/java.instrument/share/native/libinstrument/InvocationAdapter.c","lineNumber":800,"sourceCode":"/*\n * Append the given jar file to the system class path. This should succeed in the\n * onload phase but may fail in the live phase if the system class loader doesn't\n * support appending to the class path.\n */\nstatic int\nappendClassPath( JPLISAgent* agent,\n                 const char* jarfile ) {\n    jvmtiEnv* jvmtienv = jvmti(agent);\n    jvmtiError jvmtierr;\n\n    jvmtierr = (*jvmtienv)->AddToSystemClassLoaderSearch(jvmtienv, jarfile);\n    check_phase_ret_1(jvmtierr);\n\n    switch (jvmtierr) {\n        case JVMTI_ERROR_NONE :\n            return 0;\n        case JVMTI_ERROR_CLASS_LOADER_UNSUPPORTED :\n            fprintf(stderr, \"System class loader does not define \"\n                \"the appendToClassPathForInstrumentation method\\n\");\n            break;\n        default:\n            fprintf(stderr, \"Unexpected error (%d) returned by \"\n                \"AddToSystemClassLoaderSearch\\n\", jvmtierr);\n            break;\n    }\n    return -1;\n}\n\n\n/*\n * res = func, free'ing the previous value of 'res' if function\n * returns a new result.\n */\n#define TRANSFORM(res,func) {    \\\n    char* tmp = func;            \\\n    if (tmp != res) {            \\","sourceCodeStart":782,"sourceCodeEnd":818,"githubUrl":"https://github.com/openjdk/jdk/blob/88dfb74bbeefcf2b0aa11835183bcd949998fc8f/src/java.instrument/share/native/libinstrument/InvocationAdapter.c#L782-L818","documentation":"Diagnostic printed by appendClassPath: JVMTI AddToSystemClassLoaderSearch returned JVMTI_ERROR_CLASS_LOADER_UNSUPPORTED, meaning the system class loader does not define (or did not accept) appendToClassPathForInstrumentation. appendClassPath returns -1, which callers turn into either a fatal premain abort (startup) or AGENT_ERROR_NOTONCP (attach).","triggerScenarios":"-javaagent at launch or VirtualMachine.loadAgent at runtime while the system class loader is a custom class that does not support appending to its search path.","commonSituations":"-Djava.system.class.loader with app-server/framework loaders; environments that deliberately lock the system classpath for security.","solutions":["Use the default system class loader (remove -Djava.system.class.loader)","Make the custom loader extend URLClassLoader or implement the append behavior","Place agent classes on the initial classpath so no append is required","For frameworks with dedicated agent support, use their integration point instead of attach"],"exampleFix":"// before\nclass IsolatingLoader extends ClassLoader { ... } // used as java.system.class.loader\n// after\nclass IsolatingLoader extends URLClassLoader { ... } // append-capable","handlingStrategy":"validation","validationCode":"// guard: only attach when the system loader can append\nClassLoader sys = ClassLoader.getSystemClassLoader();\nboolean appendable = false;\ntry { appendable = ClassLoader.class.getMethod(\"appendToClassPathForInstrumentation\", String.class) != null; } catch (NoSuchMethodException ignored) {}\nif (!appendable) throw new UnsupportedOperationException(\"system loader not appendable: \" + sys.getClass().getName());","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Avoid -Djava.system.class.loader unless the loader explicitly supports instrumentation","Keep the default AppClassLoader for processes that host attach-based tooling"],"tags":["java-instrument","classloader","jvmti","classpath","configuration"],"backgroundTag":null,"analyzedSha":"88dfb74bbeefcf2b0aa11835183bcd949998fc8f","analyzedAt":"2026-08-14T11:45:09.665Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}