{"record":{"id":"d8cc85dbc522434d","repo":"apache/dubbo","slug":"the-instance-is-not-a-class-wrapper","errorCode":null,"errorMessage":"The instance is not a class wrapper","messagePattern":"The instance is not a class wrapper","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"warning","filePath":"dubbo-common/src/main/java/org/apache/dubbo/common/beanutil/JavaBeanDescriptor.java","lineNumber":144,"sourceCode":"            return result == null ? null : result.toString();\n        }\n        throw new IllegalStateException(\"The instance is not a enum wrapper\");\n    }\n\n    public String getEnumPropertyName() {\n        if (isEnumType()) {\n            Object result = getProperty(ENUM_PROPERTY_NAME);\n            return result == null ? null : result.toString();\n        }\n        throw new IllegalStateException(\"The instance is not a enum wrapper\");\n    }\n\n    public String setClassNameProperty(String name) {\n        if (isClassType()) {\n            Object result = setProperty(CLASS_PROPERTY_NAME, name);\n            return result == null ? null : result.toString();\n        }\n        throw new IllegalStateException(\"The instance is not a class wrapper\");\n    }\n\n    public String getClassNameProperty() {\n        if (isClassType()) {\n            Object result = getProperty(CLASS_PROPERTY_NAME);\n            return result == null ? null : result.toString();\n        }\n        throw new IllegalStateException(\"The instance is not a class wrapper\");\n    }\n\n    public Object setPrimitiveProperty(Object primitiveValue) {\n        if (isPrimitiveType()) {\n            return setProperty(PRIMITIVE_PROPERTY_VALUE, primitiveValue);\n        }\n        throw new IllegalStateException(\"The instance is not a primitive type wrapper\");\n    }\n\n    public Object getPrimitiveProperty() {","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/apache/dubbo/blob/3a3043227f5571d25eb2889de5bca22f2914843b/dubbo-common/src/main/java/org/apache/dubbo/common/beanutil/JavaBeanDescriptor.java#L126-L162","documentation":"Thrown by JavaBeanDescriptor.setClassNameProperty when the descriptor's type is not TYPE_CLASS. The class-name property is only valid on class wrappers; calling the setter on an enum/primitive/collection/map/array/bean descriptor (or the default type-0 descriptor) is a programming error, so it fails with IllegalStateException.","triggerScenarios":"desc.setClassNameProperty(name) on a JavaBeanDescriptor whose type is not TYPE_CLASS (e.g. TYPE_ENUM, TYPE_PRIMITIVE, or default 0).","commonSituations":"Generic builder code calling class mutators unconditionally; reusing descriptors across types; deserialized descriptor whose type does not match the expected kind; refactoring changing a type constant.","solutions":["Construct the descriptor as a class: new JavaBeanDescriptor(className, JavaBeanDescriptor.TYPE_CLASS) before calling setClassNameProperty.","Guard with if (desc.isClassType()) before calling class mutators.","Branch on descriptor type in generic processing code.","Create a new descriptor of the correct type instead of reusing an existing one for a different kind."],"exampleFix":"// before\nJavaBeanDescriptor desc = new JavaBeanDescriptor();\ndesc.setClassNameProperty(\"com.foo.Bar\");  // throws, type is 0\n// after\nJavaBeanDescriptor desc = new JavaBeanDescriptor(\"com.foo.Bar\", JavaBeanDescriptor.TYPE_CLASS);\ndesc.setClassNameProperty(\"com.foo.Bar\");","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"// Only set class name when the descriptor is actually a class wrapper\nboolean canSetClassName(JavaBeanDescriptor d) {\n    return d.isClassType();\n}","tryCatchPattern":null,"preventionTips":["Guard class mutators with isClassType().","Construct descriptors with TYPE_CLASS when a class wrapper is intended.","Do not reuse a descriptor for a different kind; recreate it with the right type.","Branch on descriptor type in generic code."],"tags":["beanutil","type-state","class-wrapper","dubbo-common"],"backgroundTag":null,"analyzedSha":"3a3043227f5571d25eb2889de5bca22f2914843b","analyzedAt":"2026-08-14T00:43:19.853Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}