{"record":{"id":"f880f2010d15c380","repo":"alibaba/Sentinel","slug":"bad-invocation-instance-f880f2","errorCode":null,"errorMessage":"Bad invocation instance","messagePattern":"Bad invocation instance","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sentinel-adapter/sentinel-apache-dubbo3-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/dubbo3/DubboUtils.java","lineNumber":37,"sourceCode":"import com.alibaba.csp.sentinel.util.StringUtil;\n\nimport org.apache.dubbo.common.utils.StringUtils;\nimport org.apache.dubbo.rpc.Invocation;\nimport org.apache.dubbo.rpc.Invoker;\nimport org.apache.dubbo.rpc.RpcContext;\n\nimport static org.apache.dubbo.common.constants.CommonConstants.REMOTE_APPLICATION_KEY;\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        // 1. try to get application from dubbo context\n        String remoteApplication = invocation.getAttachment(REMOTE_APPLICATION_KEY);\n        if (StringUtils.isEmpty(remoteApplication)) {\n            remoteApplication = RpcContext.getServerAttachment().getAttachment(REMOTE_APPLICATION_KEY);\n        }\n        if (StringUtils.isNotEmpty(remoteApplication)) {\n            return remoteApplication;\n        }\n        // 2. fallback to sentinel application\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) {","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/alibaba/Sentinel/blob/a3f40ba8e900c8489bd520274739f17235a7721c/sentinel-adapter/sentinel-apache-dubbo3-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/dubbo3/DubboUtils.java#L19-L55","documentation":"Thrown by DubboUtils.getApplication() in the Sentinel Apache Dubbo 3.x adapter when the Invocation is null or its attachments map is null. The adapter resolves the caller's application name: first from the Dubbo 'remoteApplication' attachment (also falling back to RpcContext.getServerAttachment()), then from the legacy 'dubboApplication' attachment. A null Invocation or null attachment map cannot be processed, so it fails fast with IllegalArgumentException.","triggerScenarios":"Calling DubboUtils.getApplication(null, default) directly; passing an Invocation whose getAttachments() returns null; invoking the adapter's filters in unit tests without a real Dubbo 3 RPC context (RpcContext.getServerAttachment() empty and unstubbed Invocation).","commonSituations":"Migrating from Dubbo 2.x to Dubbo 3 adapter where mocks no longer match; unit tests of Dubbo3 filters lacking stubbed attachments; custom filters wrapping Invocation and dropping attachments.","solutions":["Null-guard before calling: only invoke getApplication when invocation != null && invocation.getAttachments() != null","In tests, stub both invocation.getAttachments() and (if needed) RpcContext.getServerAttachment() to return non-null maps","Ensure the Sentinel Dubbo 3 filter is on the provider/consumer filter chain after Dubbo's context-establishing filters"],"exampleFix":"// before\nString app = DubboUtils.getApplication(invocation, defaultValue);\n\n// after\nString app = (invocation != null && invocation.getAttachments() != null)\n    ? DubboUtils.getApplication(invocation, defaultValue)\n    : defaultValue;","handlingStrategy":"validation","validationCode":"if (invocation == null || invocation.getAttachments() == null) {\n    return defaultValue;\n}\nreturn DubboUtils.getApplication(invocation, defaultValue);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Stub both invocation attachments and RpcContext.getServerAttachment() in Dubbo 3 tests","Confirm filter order so the Sentinel filter sees a fully initialized Invocation"],"tags":["dubbo3","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"}