{"record":{"id":"15f90bb548e97f4b","repo":"Netflix/Hystrix","slug":"failed-trying-to-wrap-constructor-of-class-cl","errorCode":null,"errorMessage":"Failed trying to wrap constructor of class: \" + className","messagePattern":"Failed trying to wrap constructor of class: \" \\+ className","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"critical","filePath":"hystrix-contrib/hystrix-network-auditor-agent/src/main/java/com/netflix/hystrix/contrib/networkauditor/NetworkClassTransform.java","lineNumber":94,"sourceCode":"     * Wrap all signatures of a given method name.\n     * \n     * @param className\n     * @param methodName\n     * @throws NotFoundException\n     * @throws CannotCompileException\n     * @throws IOException\n     */\n    private byte[] wrapClass(String className, boolean wrapConstructors, String... methodNames) throws NotFoundException, IOException, CannotCompileException {\n        ClassPool cp = ClassPool.getDefault();\n        CtClass ctClazz = cp.get(className);\n        // constructors\n        if (wrapConstructors) {\n            CtConstructor[] constructors = ctClazz.getConstructors();\n            for (CtConstructor constructor : constructors) {\n                try {\n                    constructor.insertBefore(\"{ com.netflix.hystrix.contrib.networkauditor.HystrixNetworkAuditorAgent.notifyOfNetworkEvent(); }\");\n                } catch (Exception e) {\n                    throw new RuntimeException(\"Failed trying to wrap constructor of class: \" + className, e);\n                }\n\n            }\n        }\n        // methods\n        CtMethod[] methods = ctClazz.getDeclaredMethods();\n        for (CtMethod method : methods) {\n            try {\n                for (String methodName : methodNames) {\n                    if (method.getName().equals(methodName)) {\n                        method.insertBefore(\"{ com.netflix.hystrix.contrib.networkauditor.HystrixNetworkAuditorAgent.handleNetworkEvent(); }\");\n                    }\n                }\n            } catch (Exception e) {\n                throw new RuntimeException(\"Failed trying to wrap method [\" + method.getName() + \"] of class: \" + className, e);\n            }\n        }\n        return ctClazz.toBytecode();","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/Netflix/Hystrix/blob/5ce3bc58c38e7ca60ef2fe0e516e390e294ad941/hystrix-contrib/hystrix-network-auditor-agent/src/main/java/com/netflix/hystrix/contrib/networkauditor/NetworkClassTransform.java#L76-L112","documentation":"Inside NetworkClassTransform.wrapClass, each CtConstructor of the class being instrumented gets a call to constructor.insertBefore injecting the notifyOfNetworkEvent() hook. If inserting the snippet fails for any single constructor (Javassist CannotCompileException or verification issues on synthetic/obfuscated constructors), the loop aborts with RuntimeException('Failed trying to wrap constructor of class: <name>') identifying the class whose constructor could not be wrapped.","triggerScenarios":"Javassist rejecting the injected source on a constructor with unusual bytecode (synthetic constructors, JIT/obfuscator-generated classes, newer JDK constructor idioms); class pool resolving a different class version than the one being defined by the class loader.","commonSituations":"Same deployment contexts as the class-level wrap failure: newer JDKs, obfuscated builds, frameworks that redefine Socket-related classes (other agents like APM tools transforming the same classes first).","solutions":["Inspect the nested cause (CannotCompileException detail) to see which constructor failed and why","Resolve agent conflicts: ensure no other javaagent (APM/profiling) transforms java.net/nio classes before this one, or order the agents so instrumentation composes","Run on a supported JDK/agent version combination","If unresolvable, disable/remove the network auditor agent — the app cannot start while transformation throws"],"exampleFix":"# before (two agents fighting over java.nio.channels.SocketChannel)\njava -javaagent:apm-agent.jar -javaagent:hystrix-network-auditor-agent.jar -jar app.jar\n\n# after (drop the auditor, keep the supported APM agent)\njava -javaagent:apm-agent.jar -jar app.jar","handlingStrategy":"try-catch","validationCode":"if (Instrumentation.class.isInstance(inst)) {\n    // verify the target class shape before adding transformer\n    try { ClassPool.getDefault().get(\"java.nio.channels.SocketChannel\"); }\n    catch (NotFoundException e) { log.warn(\"auditor: expected hook class missing — skip instrumentation\"); }\n}","typeGuard":null,"tryCatchPattern":"// inside the transformer loop: per-constructor isolation instead of aborting the class\nfor (CtConstructor c : constructors) {\n    try { c.insertBefore(HOOK); }\n    catch (Exception e) { log.warn(\"skip constructor {} of {}: {}\", c, className, e.getMessage()); }\n}","preventionTips":["Test the agent against the exact JDK build in CI","Avoid running multiple bytecode agents over java.net/java.nio classes; fix the agent order","Treat any transformation RuntimeException as a compatibility signal — capture the nested CannotCompileException cause for diagnosis"],"tags":["hystrix","network-auditor","javaagent","javassist","instrumentation","constructor"],"backgroundTag":null,"analyzedSha":"5ce3bc58c38e7ca60ef2fe0e516e390e294ad941","analyzedAt":"2026-08-14T10:55:35.600Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}