{"record":{"id":"e16c7eba4effa195","repo":"alibaba/nacos","slug":"can-t-parse-out-groupname-but-it-must-not-be-nul","errorCode":null,"errorMessage":"Can't parse out 'groupName',but it must not be null!","messagePattern":"Can't parse out 'groupName',but it must not be null!","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"api/src/main/java/com/alibaba/nacos/api/naming/pojo/ServiceInfo.java","lineNumber":102,"sourceCode":"        this.allIps = allIps;\n    }\n    \n    /**\n     * There is only one form of the key:groupName@@name@@clusters. This constructor used by DiskCache.read(String) and\n     * FailoverReactor.FailoverFileReader,you should know that 'groupName' must not be null,and 'clusters' can be null.\n     */\n    public ServiceInfo(final String key) {\n        String[] keys = key.split(Constants.SERVICE_INFO_SPLITER);\n        if (keys.length >= FILE_NAME_PARTS) {\n            this.groupName = keys[GROUP_POSITION];\n            this.name = keys[SERVICE_POSITION];\n            this.clusters = keys[CLUSTER_POSITION];\n        } else if (keys.length == CLUSTER_POSITION) {\n            this.groupName = keys[GROUP_POSITION];\n            this.name = keys[SERVICE_POSITION];\n        } else {\n            //defensive programming\n            throw new IllegalArgumentException(\n                \"Can't parse out 'groupName',but it must not be null!\");\n        }\n    }\n    \n    public ServiceInfo(String name, String clusters) {\n        this.name = name;\n        this.clusters = clusters;\n    }\n    \n    public int ipCount() {\n        return hosts.size();\n    }\n    \n    public boolean expired() {\n        return System.currentTimeMillis() - lastRefTime > cacheMillis;\n    }\n    \n    public void setHosts(List<Instance> hosts) {","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/api/src/main/java/com/alibaba/nacos/api/naming/pojo/ServiceInfo.java#L84-L120","documentation":"ServiceInfo(String key) splits a composite key by '@@'. It needs at least GROUP_POSITION and SERVICE_POSITION parts to recover groupName and name. If the split yields fewer parts than CLUSTER_POSITION (defensive branch), it throws IllegalArgumentException because groupName cannot be safely derived.","triggerScenarios":"Constructing new ServiceInfo(\"my-service\") with a bare name; reading a corrupted cache filename that lost its '@@' separators; passing a plain serviceName where a grouped key is expected.","commonSituations":"Service-info cache file rebuilt incorrectly after a version change; client code confusing serviceName with the composite key; manually crafted keys missing the group segment.","solutions":["Pass a key in the form 'group@@name' or 'group@@name@@clusters'.","Use the ServiceInfo(name, clusters) constructor when you only have a plain name.","Build keys via NamingUtils.getServiceKey(...) / getGroupedName(...) rather than hand-concatenating."],"exampleFix":"// before\nServiceInfo info = new ServiceInfo(\"my-service\");  // throws 541\n\n// after\nServiceInfo info = new ServiceInfo(\"DEFAULT_GROUP@@my-service@@DEFAULT\");","handlingStrategy":"validation","validationCode":"String[] parts = key.split(Constants.SERVICE_INFO_SPLITER);\nif (parts.length < 2) {\n    throw new IllegalArgumentException(\"key must be at least 'group@@name'\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    return new ServiceInfo(key);\n} catch (IllegalArgumentException e) {\n    // rebuild a valid key from explicit group + name\n    return new ServiceInfo(NamingUtils.getGroupedName(name, group), clusters);\n}","preventionTips":["Never pass a bare serviceName to ServiceInfo(String).","Build keys via NamingUtils.getServiceKey / getGroupedName.","Use ServiceInfo(name, clusters) when you only have a plain name."],"tags":["naming","parsing","service-key","defensive"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}