{"record":{"id":"73925839ecfeda55","repo":"apache/dubbo","slug":"the-instance-is-not-a-enum-wrapper","errorCode":null,"errorMessage":"The instance is not a enum wrapper","messagePattern":"The instance is not a enum wrapper","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"warning","filePath":"dubbo-common/src/main/java/org/apache/dubbo/common/beanutil/JavaBeanDescriptor.java","lineNumber":128,"sourceCode":"    public String getClassName() {\n        return className;\n    }\n\n    public void setClassName(String className) {\n        this.className = className;\n    }\n\n    public Object setProperty(Object propertyName, Object propertyValue) {\n        notNull(propertyName, \"Property name is null\");\n        return properties.put(propertyName, propertyValue);\n    }\n\n    public String setEnumNameProperty(String name) {\n        if (isEnumType()) {\n            Object result = setProperty(ENUM_PROPERTY_NAME, 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 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","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/apache/dubbo/blob/3a3043227f5571d25eb2889de5bca22f2914843b/dubbo-common/src/main/java/org/apache/dubbo/common/beanutil/JavaBeanDescriptor.java#L110-L146","documentation":"Thrown by JavaBeanDescriptor.setEnumNameProperty when the descriptor's type is not TYPE_ENUM. Enum-specific mutators are only valid on enum wrappers; calling them on a class/primitive/collection/map/array/bean descriptor is a programming error, so the method refuses with IllegalStateException.","triggerScenarios":"desc.setEnumNameProperty(name) on a JavaBeanDescriptor constructed with a type other than TYPE_ENUM (e.g. TYPE_CLASS, TYPE_PRIMITIVE, or the default no-arg constructor whose type defaults to 0).","commonSituations":"Reusing a descriptor for a different kind without recreating it; building descriptors generically and calling the wrong mutator; default-constructed descriptor (type 0) being treated as an enum; refactoring that changed a type constant.","solutions":["Construct the descriptor as an enum: new JavaBeanDescriptor(className, JavaBeanDescriptor.TYPE_ENUM) before calling setEnumNameProperty.","Guard with if (desc.isEnumType()) before calling enum mutators.","Do not reuse a descriptor across types; create a fresh one with the correct type.","Verify the type field after deserialization before invoking type-specific methods."],"exampleFix":"// before\nJavaBeanDescriptor desc = new JavaBeanDescriptor();  // type defaults to 0\ndesc.setEnumNameProperty(\"RED\");  // throws\n// after\nJavaBeanDescriptor desc = new JavaBeanDescriptor(Color.class.getName(), JavaBeanDescriptor.TYPE_ENUM);\ndesc.setEnumNameProperty(\"RED\");","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"// Only set enum name when the descriptor is actually an enum wrapper\nboolean canSetEnumName(JavaBeanDescriptor d) {\n    return d.isEnumType();\n}","tryCatchPattern":null,"preventionTips":["Construct descriptors with the correct TYPE_* before calling type-specific mutators.","Guard enum mutators with isEnumType().","Never reuse a descriptor across types; create a fresh one.","Validate the type after deserialization before invoking type-specific methods."],"tags":["beanutil","enum","type-state","dubbo-common"],"backgroundTag":null,"analyzedSha":"3a3043227f5571d25eb2889de5bca22f2914843b","analyzedAt":"2026-08-14T00:43:19.853Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}