{"record":{"id":"e7b58c6a4e66ee4a","repo":"Netflix/Hystrix","slug":"hystrixnetworkauditoreventlistener-can-not-be-null","errorCode":null,"errorMessage":"HystrixNetworkAuditorEventListener can not be NULL","messagePattern":"HystrixNetworkAuditorEventListener can not be NULL","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hystrix-contrib/hystrix-network-auditor-agent/src/main/java/com/netflix/hystrix/contrib/networkauditor/HystrixNetworkAuditorAgent.java","lineNumber":54,"sourceCode":"        inst.addTransformer(new NetworkClassTransform());\n    }\n\n    /**\n     * Invoked by instrumented code when network access occurs.\n     */\n    public static void notifyOfNetworkEvent() {\n        bridge.handleNetworkEvent();\n    }\n\n    /**\n     * Register the implementation of the {@link HystrixNetworkAuditorEventListener} that will receive the events.\n     * \n     * @param bridge\n     *            {@link HystrixNetworkAuditorEventListener} implementation\n     */\n    public static void registerEventListener(HystrixNetworkAuditorEventListener bridge) {\n        if (bridge == null) {\n            throw new IllegalArgumentException(\"HystrixNetworkAuditorEventListener can not be NULL\");\n        }\n        HystrixNetworkAuditorAgent.bridge = bridge;\n    }\n\n}\n","sourceCodeStart":36,"sourceCodeEnd":60,"githubUrl":"https://github.com/Netflix/Hystrix/blob/5ce3bc58c38e7ca60ef2fe0e516e390e294ad941/hystrix-contrib/hystrix-network-auditor-agent/src/main/java/com/netflix/hystrix/contrib/networkauditor/HystrixNetworkAuditorAgent.java#L36-L60","documentation":"HystrixNetworkAuditorAgent is a javaagent that forwards socket/NIO activity to a registered HystrixNetworkAuditorEventListener (the 'bridge'). registerEventListener guards its single required argument with an explicit null check throwing IllegalArgumentException, because a null bridge would silently disable all network-event auditing.","triggerScenarios":"Calling HystrixNetworkAuditorAgent.registerEventListener(null) — typically from agent premain/application boot code that failed to construct the listener (e.g. dependency injection returned null, or a config-driven conditional listener that was never created).","commonSituations":"Wiring the auditor agent in a DI container where the listener bean is missing/conditional; test harnesses registering a no-op that evaluates to null; refactoring listener construction so the instance is created after registration is attempted.","solutions":["Fix the construction path so the listener instance is non-null before registering (check the DI bean exists)","Register defensively only when the listener is available, failing fast with a clear boot error if the auditor is enabled without a listener","Pass a no-op implementation rather than null if auditing is optional in some profiles","Add a startup assertion/log immediately after registration"],"exampleFix":"// before\nHystrixNetworkAuditorAgent.registerEventListener(listenerBean()); // may return null\n\n// after\nHystrixNetworkAuditorEventListener listener = listenerBean();\nif (listener == null) throw new IllegalStateException(\"network auditor enabled but no listener configured\");\nHystrixNetworkAuditorAgent.registerEventListener(listener);","handlingStrategy":"validation","validationCode":"if (listener == null) {\n    throw new IllegalStateException(\"Network auditor enabled but listener is null — check DI wiring\");\n}\nHystrixNetworkAuditorAgent.registerEventListener(listener);","typeGuard":"null // Java: use Objects.requireNonNull; no type-narrowing involved\nObjects.requireNonNull(listener, \"auditor listener\");","tryCatchPattern":"catch (IllegalArgumentException e) { log.error(\"registerEventListener(null) — fix listener construction\", e); failBoot(e); }","preventionTips":["Fail fast if the auditor is enabled without a listener bean","Register in the same place the listener is constructed","Pass a no-op listener for disabled profiles instead of null"],"tags":["hystrix","network-auditor","javaagent","null-check","listener"],"backgroundTag":null,"analyzedSha":"5ce3bc58c38e7ca60ef2fe0e516e390e294ad941","analyzedAt":"2026-08-14T10:55:35.600Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}