{"record":{"id":"2e6509a6dbd82f8b","repo":"Netflix/Hystrix","slug":"failed-trying-to-wrap-class-classname","errorCode":null,"errorMessage":"Failed trying to wrap class: \" + className","messagePattern":"Failed trying to wrap 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":56,"sourceCode":"        try {\n            /*\n             * These hook points were found through trial-and-error after wrapping all java.net/java.io/java.nio classes and methods and finding reliable\n             * notifications that matched statistics and events in an application.\n             * \n             * There may very well be problems here or code paths that don't correctly trigger an event.\n             * \n             * If someone can provide a more reliable and cleaner hook point or if there are examples of code paths that don't trigger either of these\n             * then please file a bug or submit a pull request at https://github.com/Netflix/Hystrix\n             */\n            if (name.equals(\"java.net.Socket$2\")) {\n                // this one seems to be fairly reliable in counting each time a request/response occurs on blocking IO\n                return wrapConstructorsOfClass(name);\n            } else if (name.equals(\"java.nio.channels.SocketChannel\")) {\n                // handle NIO \n                return wrapConstructorsOfClass(name);\n            }\n        } catch (Exception e) {\n            throw new RuntimeException(\"Failed trying to wrap class: \" + className, e);\n        }\n\n        // we didn't transform anything so return null to leave untouched\n        return null;\n    }\n\n    /**\n     * Wrap all constructors of a given class\n     * \n     * @param className\n     * @throws NotFoundException\n     * @throws CannotCompileException\n     * @throws IOException\n     */\n    private byte[] wrapConstructorsOfClass(String className) throws NotFoundException, IOException, CannotCompileException {\n        return wrapClass(className, true);\n    }\n","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/Netflix/Hystrix/blob/5ce3bc58c38e7ca60ef2fe0e516e390e294ad941/hystrix-contrib/hystrix-network-auditor-agent/src/main/java/com/netflix/hystrix/contrib/networkauditor/NetworkClassTransform.java#L38-L74","documentation":"NetworkClassTransform is the javaagent's ClassFileTransformer: when the JVM loads java.net.Socket$2 or java.nio.channels.SocketChannel it uses Javassist (ClassPool/CtClass) to instrument them so each network operation notifies HystrixNetworkAuditorAgent. Any Exception during lookup or transformation (e.g. a JDK whose internal Socket$2 differs, ClassPool missing the class path, CtClass compilation failure) is wrapped in RuntimeException('Failed trying to wrap class: <name>').","triggerScenarios":"Running the network-auditor agent on an unsupported/newer JDK where java.net.Socket$2 internals changed or the anonymous class name differs; ClassPool.getDefault() unable to resolve bootstrap classes (missing -Xbootclasspath inclusion of javassist's search path); Javassist CannotCompileException from inserting before an incompatible constructor.","commonSituations":"Upgrading the application to a newer Java version while keeping an old hystrix-network-auditor-agent; running on non-HotSpot JVMs; agent jar missing javassist or its classpool configuration on restricted classloaders.","solutions":["Pin or move to a Java version the agent supports (the transformation targets specific JDK internals of its era)","Upgrade hystrix-network-auditor-agent (or drop the auditor) if the JDK internal class it hooks no longer exists — inspect the cause in the stack trace","Ensure the agent jar and its javassist dependency are on the boot path: -javaagent:...agent.jar with javassist bundled","If the auditor is not essential, remove the -javaagent flag to unblock startup"],"exampleFix":"# before (newer JDK, agent fails transforming JDK internals)\njava -javaagent:hystrix-network-auditor-agent-1.5.x.jar -jar app.jar\n\n# after (remove unsupported agent or use supported JDK)\njava -jar app.jar","handlingStrategy":"try-catch","validationCode":"String javaVersion = System.getProperty(\"java.specification.version\");\nif (!SUPPORTED_JDKS.contains(javaVersion)) {\n    log.warn(\"network-auditor agent unsupported on JDK {} — remove -javaagent or upgrade agent\", javaVersion);\n}","typeGuard":null,"tryCatchPattern":"// in agent bootstrap/premain: isolate and surface transformation failures\ntry { premainLogic(args, instrumentation); }\ncatch (RuntimeException e) {\n    log.error(\"network auditor transformation failed ({}); continuing without auditing\", e.getMessage(), e);\n    // or fail hard if auditing is mandatory: throw e;\n}","preventionTips":["Pin the JDK version validated for the agent","Bundle javassist inside the agent jar and verify -javaagent order","Smoke-test the agent in a staging JVM identical to production before rollout"],"tags":["hystrix","network-auditor","javaagent","javassist","jdk-compatibility","instrumentation"],"backgroundTag":null,"analyzedSha":"5ce3bc58c38e7ca60ef2fe0e516e390e294ad941","analyzedAt":"2026-08-14T10:55:35.600Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}