{"record":{"id":"a69f2cc1342fafa8","repo":"alibaba/Sentinel","slug":"bad-invocation-instance","errorCode":null,"errorMessage":"Bad invocation instance","messagePattern":"Bad invocation instance","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sentinel-adapter/sentinel-apache-dubbo-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/dubbo/DubboUtils.java","lineNumber":32,"sourceCode":" * limitations under the License.\n */\npackage com.alibaba.csp.sentinel.adapter.dubbo;\n\nimport com.alibaba.csp.sentinel.adapter.dubbo.config.DubboAdapterGlobalConfig;\nimport com.alibaba.csp.sentinel.util.StringUtil;\nimport org.apache.dubbo.rpc.Invocation;\nimport org.apache.dubbo.rpc.Invoker;\n\n/**\n * @author Eric Zhao\n */\npublic final class DubboUtils {\n\n    public static final String SENTINEL_DUBBO_APPLICATION_KEY = \"dubboApplication\";\n\n    public static String getApplication(Invocation invocation, String defaultValue) {\n        if (invocation == null || invocation.getAttachments() == null) {\n            throw new IllegalArgumentException(\"Bad invocation instance\");\n        }\n        return invocation.getAttachment(SENTINEL_DUBBO_APPLICATION_KEY, defaultValue);\n    }\n\n    public static String getMethodResourceName(Invoker<?> invoker, Invocation invocation){\n        return getMethodResourceName(invoker, invocation, false);\n    }\n\n    public static String getMethodResourceName(Invoker<?> invoker, Invocation invocation, Boolean useGroupAndVersion) {\n        StringBuilder buf = new StringBuilder(64);\n        String interfaceResource = useGroupAndVersion ? invoker.getUrl().getColonSeparatedKey() : invoker.getInterface().getName();\n        buf.append(interfaceResource)\n            .append(\":\")\n            .append(invocation.getMethodName())\n            .append(\"(\");\n        boolean isFirst = true;\n        for (Class<?> clazz : invocation.getParameterTypes()) {\n            if (!isFirst) {","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/alibaba/Sentinel/blob/a3f40ba8e900c8489bd520274739f17235a7721c/sentinel-adapter/sentinel-apache-dubbo-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/dubbo/DubboUtils.java#L14-L50","documentation":"Thrown by DubboUtils.getApplication() in the Sentinel Apache Dubbo 2.x adapter when the passed org.apache.dubbo.rpc.Invocation is null or its attachment map is null. The utility reads the consumer application name from the 'dubboApplication' attachment on every Dubbo invocation for flow-control origin tracking, so a malformed Invocation is rejected immediately with IllegalArgumentException. It signals a programming error or a broken filter chain, not a runtime flow event.","triggerScenarios":"Calling DubboUtils.getApplication(null, default) or getApplication(invocation, default) where invocation.getAttachments() returns null; indirectly via SentinelDubboProviderFilter/ConsumerFilter when a custom Dubbo filter replaced or wrapped the Invocation with one that has no attachment map.","commonSituations":"Unit tests with mocked Invocation objects that don't stub getAttachments(); custom Dubbo filter ordering that puts Sentinel's filter before the RPC framework populates attachments; upgrading Dubbo versions where the Invocation implementation differs.","solutions":["If you called DubboUtils directly, guard with 'if (invocation == null || invocation.getAttachments() == null) return default;' before calling","In unit tests, stub the mock: when(invocation.getAttachments()).thenReturn(new HashMap<>())","Check custom Dubbo filter order (sentinel.adapter.filter.order) so the Sentinel filter runs after Dubbo's own context filters","Verify you are not passing an InvokerInvocationHandler-created invocation before the RPC layer initialized it"],"exampleFix":"// before\nString app = DubboUtils.getApplication(invocation, \"default\");\n\n// after\nString app = (invocation != null && invocation.getAttachments() != null)\n    ? DubboUtils.getApplication(invocation, \"default\")\n    : \"default\";","handlingStrategy":"validation","validationCode":"if (invocation == null || invocation.getAttachments() == null) {\n    return defaultValue;\n}\nreturn DubboUtils.getApplication(invocation, defaultValue);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always null-check Invocation and its attachment map before calling adapter utilities","In unit tests, stub getAttachments() to return a HashMap rather than leaving it default (null)"],"tags":["dubbo","adapter","illegal-argument","null-check","rpc"],"backgroundTag":null,"analyzedSha":"a3f40ba8e900c8489bd520274739f17235a7721c","analyzedAt":"2026-08-14T11:10:30.678Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}