Netflix/Hystrix · critical · RuntimeException

Failed trying to wrap constructor of class: " + className

Error message

Failed trying to wrap constructor of class: " + className

What it means

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.

Source

Thrown at hystrix-contrib/hystrix-network-auditor-agent/src/main/java/com/netflix/hystrix/contrib/networkauditor/NetworkClassTransform.java:94

     * Wrap all signatures of a given method name.
     * 
     * @param className
     * @param methodName
     * @throws NotFoundException
     * @throws CannotCompileException
     * @throws IOException
     */
    private byte[] wrapClass(String className, boolean wrapConstructors, String... methodNames) throws NotFoundException, IOException, CannotCompileException {
        ClassPool cp = ClassPool.getDefault();
        CtClass ctClazz = cp.get(className);
        // constructors
        if (wrapConstructors) {
            CtConstructor[] constructors = ctClazz.getConstructors();
            for (CtConstructor constructor : constructors) {
                try {
                    constructor.insertBefore("{ com.netflix.hystrix.contrib.networkauditor.HystrixNetworkAuditorAgent.notifyOfNetworkEvent(); }");
                } catch (Exception e) {
                    throw new RuntimeException("Failed trying to wrap constructor of class: " + className, e);
                }

            }
        }
        // methods
        CtMethod[] methods = ctClazz.getDeclaredMethods();
        for (CtMethod method : methods) {
            try {
                for (String methodName : methodNames) {
                    if (method.getName().equals(methodName)) {
                        method.insertBefore("{ com.netflix.hystrix.contrib.networkauditor.HystrixNetworkAuditorAgent.handleNetworkEvent(); }");
                    }
                }
            } catch (Exception e) {
                throw new RuntimeException("Failed trying to wrap method [" + method.getName() + "] of class: " + className, e);
            }
        }
        return ctClazz.toBytecode();

View on GitHub (pinned to 5ce3bc58c3)

Solutions

  1. Inspect the nested cause (CannotCompileException detail) to see which constructor failed and why
  2. Resolve agent conflicts: ensure no other javaagent (APM/profiling) transforms java.net/nio classes before this one, or order the agents so instrumentation composes
  3. Run on a supported JDK/agent version combination
  4. If unresolvable, disable/remove the network auditor agent — the app cannot start while transformation throws

Example fix

# before (two agents fighting over java.nio.channels.SocketChannel)
java -javaagent:apm-agent.jar -javaagent:hystrix-network-auditor-agent.jar -jar app.jar

# after (drop the auditor, keep the supported APM agent)
java -javaagent:apm-agent.jar -jar app.jar
Defensive patterns

Strategy: try-catch

Validate before calling

if (Instrumentation.class.isInstance(inst)) {
    // verify the target class shape before adding transformer
    try { ClassPool.getDefault().get("java.nio.channels.SocketChannel"); }
    catch (NotFoundException e) { log.warn("auditor: expected hook class missing — skip instrumentation"); }
}

Try / catch

// inside the transformer loop: per-constructor isolation instead of aborting the class
for (CtConstructor c : constructors) {
    try { c.insertBefore(HOOK); }
    catch (Exception e) { log.warn("skip constructor {} of {}: {}", c, className, e.getMessage()); }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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).

Related errors


AI-assisted analysis of Netflix/Hystrix@5ce3bc58c3 (2026-08-14). Data as JSON: /api/errors/15f90bb548e97f4b. Report an issue: GitHub.