{"record":{"id":"d9c4d42c67c49420","repo":"alibaba/nacos","slug":"typename-must-not-be-empty","errorCode":null,"errorMessage":"typeName must not be empty","messagePattern":"typeName must not be empty","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"api/src/main/java/com/alibaba/nacos/api/utils/json/NacosJsonSubtype.java","lineNumber":49,"sourceCode":"    \n    private final String typeName;\n    \n    /**\n     * Create a new subtype registration.\n     *\n     * @param baseType base type\n     * @param subtype subtype class\n     * @param typeName wire type name\n     */\n    public NacosJsonSubtype(Class<?> baseType, Class<?> subtype, String typeName) {\n        if (baseType == null) {\n            throw new IllegalArgumentException(\"baseType must not be null\");\n        }\n        if (subtype == null) {\n            throw new IllegalArgumentException(\"subtype must not be null\");\n        }\n        if (typeName == null || typeName.length() == 0) {\n            throw new IllegalArgumentException(\"typeName must not be empty\");\n        }\n        this.baseType = baseType;\n        this.subtype = subtype;\n        this.typeName = typeName;\n    }\n    \n    /**\n     * Return base type.\n     *\n     * @return base type\n     */\n    public Class<?> getBaseType() {\n        return baseType;\n    }\n    \n    /**\n     * Return subtype.\n     *","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/api/src/main/java/com/alibaba/nacos/api/utils/json/NacosJsonSubtype.java#L31-L67","documentation":"Third guard in NacosJsonSubtype constructor: the wire typeName must be non-null and non-empty. The typeName is the discriminator written into JSON, so an empty one would make polymorphic deserialization ambiguous.","triggerScenarios":"Registering a subtype with a null or empty discriminator string (\"\").","commonSituations":"Config key for the discriminator missing; auto-generated typeName returned empty from a lookup; refactoring that dropped the typeName constant.","solutions":["Provide a non-empty discriminator string unique within the base type.","Derive typeName from a stable constant and fail fast if blank at config load time."],"exampleFix":"// before\nnew NacosJsonSubtype(Base.class, Sub.class, config.get(\"type\"));  // missing key -> null -> throws 553\n\n// after\nString t = config.get(\"type\");\nif (t == null || t.isEmpty()) throw new IllegalStateException(\"missing type discriminator\");\nnew NacosJsonSubtype(Base.class, Sub.class, t);","handlingStrategy":"validation","validationCode":"if (typeName == null || typeName.isEmpty()) {\n    throw new IllegalStateException(\"type discriminator must be configured\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Derive typeName from a stable constant.","Fail fast at config load time if the discriminator is blank."],"tags":["json","validation","subtype","plugin","constructor"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}