{"record":{"id":"8c97423a5af0eba7","repo":"alibaba/nacos","slug":"basetype-must-not-be-null","errorCode":null,"errorMessage":"baseType must not be null","messagePattern":"baseType must not be null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"api/src/main/java/com/alibaba/nacos/api/utils/json/NacosJsonSubtype.java","lineNumber":43,"sourceCode":" */\npublic final class NacosJsonSubtype {\n    \n    private final Class<?> baseType;\n    \n    private final Class<?> subtype;\n    \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() {","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/api/src/main/java/com/alibaba/nacos/api/utils/json/NacosJsonSubtype.java#L25-L61","documentation":"NacosJsonSubtype is a registration tuple (baseType, subtype, typeName) used for polymorphic JSON (de)serialization. Its constructor refuses a null baseType because the subtype registration is meaningless without the parent type to bind against.","triggerScenarios":"Programmatically registering a JSON subtype with a null baseType, typically inside an SPI/plugin that wires up custom polymorphic types.","commonSituations":"Plugin code building a subtype registry from dynamic config where the base class was never resolved; classloader issue returning null from Class.forName.","solutions":["Resolve and pass a non-null baseType Class object.","Log and skip registrations whose base class cannot be resolved instead of passing null.","Add a unit test that exercises plugin subtype registration."],"exampleFix":"// before\nregistry.register(new NacosJsonSubtype(null, MySub.class, \"mySub\"));  // throws 551\n\n// after\nif (baseType == null) { log.warn(\"base type unresolved, skipping\"); return; }\nregistry.register(new NacosJsonSubtype(baseType, MySub.class, \"mySub\"));","handlingStrategy":"validation","validationCode":"if (baseType == null) {\n    throw new IllegalStateException(\"baseType class could not be resolved\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Resolve classes via Class.forName at plugin init and skip on failure.","Unit-test plugin subtype registration on startup."],"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"}