{"record":{"id":"d9d4175401cfa6c6","repo":"apache/dubbo","slug":"the-instance-is-not-a-primitive-type-wrapper","errorCode":null,"errorMessage":"The instance is not a primitive type wrapper","messagePattern":"The instance is not a primitive type wrapper","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"warning","filePath":"dubbo-common/src/main/java/org/apache/dubbo/common/beanutil/JavaBeanDescriptor.java","lineNumber":159,"sourceCode":"            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() {\n        if (isPrimitiveType()) {\n            return getProperty(PRIMITIVE_PROPERTY_VALUE);\n        }\n        throw new IllegalStateException(\"The instance is not a primitive type wrapper\");\n    }\n\n    public Object getProperty(Object propertyName) {\n        notNull(propertyName, \"Property name is null\");\n        return properties.get(propertyName);\n    }\n\n    public boolean containsProperty(Object propertyName) {\n        notNull(propertyName, \"Property name is null\");\n        return properties.containsKey(propertyName);\n    }","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/apache/dubbo/blob/3a3043227f5571d25eb2889de5bca22f2914843b/dubbo-common/src/main/java/org/apache/dubbo/common/beanutil/JavaBeanDescriptor.java#L141-L177","documentation":"Thrown by JavaBeanDescriptor.setPrimitiveProperty when the descriptor's type is not TYPE_PRIMITIVE. Primitive value storage is only valid on primitive wrappers; calling the setter on a class/enum/collection/map/array/bean descriptor (or the default type-0 descriptor) is a programming error, so it fails with IllegalStateException.","triggerScenarios":"desc.setPrimitiveProperty(value) on a JavaBeanDescriptor whose type is not TYPE_PRIMITIVE (e.g. TYPE_CLASS, TYPE_ENUM, or default 0).","commonSituations":"Generic builder code calling primitive mutators unconditionally; reusing descriptors across types; default-constructed descriptor treated as primitive; deserialized descriptor whose type does not match the expected kind.","solutions":["Construct with TYPE_PRIMITIVE: new JavaBeanDescriptor(className, JavaBeanDescriptor.TYPE_PRIMITIVE) before calling setPrimitiveProperty.","Guard with if (desc.isPrimitiveType()) before calling primitive mutators.","Branch on descriptor type in generic processing code.","Create a new descriptor of the correct type instead of reusing one for a different kind."],"exampleFix":"// before\nJavaBeanDescriptor desc = new JavaBeanDescriptor();\ndesc.setPrimitiveProperty(42);  // throws, type is 0\n// after\nJavaBeanDescriptor desc = new JavaBeanDescriptor(\"int\", JavaBeanDescriptor.TYPE_PRIMITIVE);\ndesc.setPrimitiveProperty(42);","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"// Only set primitive value when the descriptor is actually a primitive wrapper\nboolean canSetPrimitive(JavaBeanDescriptor d) {\n    return d.isPrimitiveType();\n}","tryCatchPattern":null,"preventionTips":["Guard primitive mutators with isPrimitiveType().","Construct descriptors with TYPE_PRIMITIVE when a primitive 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","primitive","dubbo-common"],"backgroundTag":null,"analyzedSha":"3a3043227f5571d25eb2889de5bca22f2914843b","analyzedAt":"2026-08-14T00:43:19.853Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}