{"record":{"id":"ed1aeb120e7e94a4","repo":"alibaba/nacos","slug":"400-ed1aeb","errorCode":"400","errorMessage":"Instance can not be null.","messagePattern":"Instance can not be null\\.","errorType":"validation","errorClass":"NacosApiException","httpStatus":null,"severity":"error","filePath":"api/src/main/java/com/alibaba/nacos/api/naming/utils/NamingUtils.java","lineNumber":175,"sourceCode":"     */\n    public static String getGroupedNameOptional(final String serviceName, final String groupName) {\n        return groupName + Constants.SERVICE_INFO_SPLITER + serviceName;\n    }\n    \n    /**\n     * <p>Check instance param about keep alive.</p>\n     *\n     * <pre>\n     * heart beat timeout must > heart beat interval\n     * ip delete timeout must  > heart beat interval\n     * </pre>\n     *\n     * @param instance need checked instance\n     * @throws NacosException if check failed, throw exception\n     */\n    public static void checkInstanceIsLegal(Instance instance) throws NacosException {\n        if (null == instance) {\n            throw new NacosApiException(NacosException.INVALID_PARAM, ErrorCode.INSTANCE_ERROR,\n                \"Instance can not be null.\");\n        }\n        instance.validate();\n        if (instance.getInstanceHeartBeatTimeOut() < instance.getInstanceHeartBeatInterval()\n            || instance.getIpDeleteTimeout() < instance.getInstanceHeartBeatInterval()) {\n            throw new NacosApiException(NacosException.INVALID_PARAM, ErrorCode.INSTANCE_ERROR,\n                \"Instance 'heart beat interval' must less than 'heart beat timeout' and 'ip delete timeout'.\");\n        }\n        if (!StringUtils.isEmpty(instance.getClusterName())\n            && !CLUSTER_NAME_PATTERN.matcher(instance.getClusterName())\n                .matches()) {\n            throw new NacosApiException(NacosException.INVALID_PARAM, ErrorCode.INSTANCE_ERROR,\n                String.format(\n                    \"Instance 'clusterName' should be characters with only 0-9a-zA-Z-. (current: %s)\",\n                    instance.getClusterName()));\n        }\n    }\n    ","sourceCodeStart":157,"sourceCodeEnd":193,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/api/src/main/java/com/alibaba/nacos/api/naming/utils/NamingUtils.java#L157-L193","documentation":"checkInstanceIsLegal null-checks the Instance argument first (NacosApiException, 400, ErrorCode.INSTANCE_ERROR). Any later field access would NPE, so the method fails fast with a clear message.","triggerScenarios":"registerInstance(null); batch register whose list contains a null element; deserialization that produced a null Instance.","commonSituations":"Loop registering a list where one element failed to construct; mapping code returning null on parse error and forwarding it.","solutions":["Pass a populated Instance.","Filter nulls out of batch lists before calling batchRegisterInstance.","Return a sentinel/error from mappers instead of null."],"exampleFix":"// before\nNamingUtils.checkInstanceIsLegal(maybeNullInstance);  // throws 546\n\n// after\nif (instance == null) throw new IllegalArgumentException(\"instance required\");\nNamingUtils.checkInstanceIsLegal(instance);","handlingStrategy":"type-guard","validationCode":"if (instance == null) {\n    throw new IllegalArgumentException(\"instance must not be null\");\n}","typeGuard":"boolean isRegisterable(Instance i) {\n    return i != null && i.getIp() != null && i.getPort() > 0;\n}","tryCatchPattern":null,"preventionTips":["Filter nulls from batch lists before registering.","Make mappers return a sentinel/error object instead of null."],"tags":["naming","validation","instance","null-check"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}