{"record":{"id":"7baba36fef364bda","repo":"alibaba/nacos","slug":"400-7baba3","errorCode":"400","errorMessage":"Parameter `newMetadata` can't be null","messagePattern":"Parameter `newMetadata` can't be null","errorType":"validation","errorClass":"NacosApiException","httpStatus":null,"severity":"error","filePath":"maintainer-client/src/main/java/com/alibaba/nacos/maintainer/client/naming/NacosNamingMaintainerServiceImpl.java","lineNumber":335,"sourceCode":"        RequestResource resource = buildRequestResource(service);\n        HttpRequest httpRequest = buildRequestWithResource(resource).setHttpMethod(HttpMethod.PUT)\n            .setPath(appendQuery(Constants.AdminApiPath.NAMING_INSTANCE_ADMIN_PATH, params))\n            .build();\n        HttpRestResult<String> httpRestResult =\n            getClientHttpProxy().executeSyncHttpRequest(httpRequest);\n        Result<String> result =\n            JsonUtils.toObj(httpRestResult.getData(), new NacosTypeReference<Result<String>>() {\n            });\n        return result.getData();\n    }\n    \n    @Override\n    public InstanceMetadataBatchResult batchUpdateInstanceMetadata(Service service,\n        List<Instance> instances,\n        Map<String, String> newMetadata) throws NacosException {\n        service.validate();\n        if (Objects.isNull(newMetadata)) {\n            throw new NacosApiException(NacosException.INVALID_PARAM, ErrorCode.PARAMETER_MISSING,\n                \"Parameter `newMetadata` can't be null\");\n        }\n        if (instances.isEmpty()) {\n            return new InstanceMetadataBatchResult(Collections.emptyList());\n        }\n        for (Instance each : instances) {\n            each.validate();\n        }\n        checkEphemeral(service, instances.get(0));\n        Map<String, String> params = RequestUtil.toParameters(service, instances, newMetadata);\n        RequestResource resource = buildRequestResource(service);\n        HttpRequest httpRequest = buildRequestWithResource(resource).setHttpMethod(HttpMethod.PUT)\n            .setPath(\n                appendQuery(Constants.AdminApiPath.NAMING_INSTANCE_ADMIN_PATH + \"/metadata/batch\",\n                    params))\n            .build();\n        HttpRestResult<String> httpRestResult =\n            getClientHttpProxy().executeSyncHttpRequest(httpRequest);","sourceCodeStart":317,"sourceCodeEnd":353,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/maintainer-client/src/main/java/com/alibaba/nacos/maintainer/client/naming/NacosNamingMaintainerServiceImpl.java#L317-L353","documentation":"Thrown by NacosNameMaintainerServiceImpl.batchUpdateInstanceMetadata when the newMetadata argument is null. It is a client-side validation guard (NacosApiException, INVALID_PARAM=400, ErrorCode.PARAMETER_MISSING=10000) raised before any HTTP request is sent. The maintainer client refuses to build the batch-update request because there is no metadata to apply.","triggerScenarios":"Calling NamingMaintainerService.batchUpdateInstanceMetadata(Service, List<Instance>, Map<String,String> newMetadata) with newMetadata explicitly set to null. The check runs right after service.validate() and before the instances list is iterated.","commonSituations":"Caller computes the new metadata map from upstream config or user input that happened to be empty/uninitialized, leaving the reference null. Refactor that introduced a new call path forgetting to pass the map. Deserialization from a request body where the metadata JSON field was absent.","solutions":["Pass a non-null Map (use Collections.emptyMap() when no metadata changes are needed) before calling batchUpdateInstanceMetadata.","Add a null-check in the calling code and short-circuit with a no-op or log warning when the metadata map is null.","If the metadata source can legitimately be null, default it: newMetadata = new HashMap<>() before the call."],"exampleFix":"// before\nmaintainerService.batchUpdateInstanceMetadata(service, instances, null);\n\n// after\nMap<String,String> metadata = newMetadata == null ? Collections.emptyMap() : newMetadata;\nif (!metadata.isEmpty()) {\n    maintainerService.batchUpdateInstanceMetadata(service, instances, metadata);\n}","handlingStrategy":"validation","validationCode":"if (newMetadata == null) {\n    throw new IllegalArgumentException(\"newMetadata must not be null\");\n}\n// or short-circuit:\nMap<String, String> safeMetadata = newMetadata != null ? newMetadata : Collections.emptyMap();\nmaintainerService.batchUpdateInstanceMetadata(service, instances, safeMetadata);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use Objects.requireNonNull(newMetadata, 'newMetadata') at the call site to fail early with a clear message.","Initialize metadata maps with explicit constructors rather than leaving them null from optional computations.","Add a unit test that calls batchUpdateInstanceMetadata with an empty map to confirm the happy path does not require null."],"tags":["validation","naming","maintainer-client","null-check","metadata"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}