apache/dubbo · warning · IllegalStateException

The instance is not a primitive type wrapper

Error message

The instance is not a primitive type wrapper

What it means

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.

Source

Thrown at dubbo-common/src/main/java/org/apache/dubbo/common/beanutil/JavaBeanDescriptor.java:159

            Object result = setProperty(CLASS_PROPERTY_NAME, name);
            return result == null ? null : result.toString();
        }
        throw new IllegalStateException("The instance is not a class wrapper");
    }

    public String getClassNameProperty() {
        if (isClassType()) {
            Object result = getProperty(CLASS_PROPERTY_NAME);
            return result == null ? null : result.toString();
        }
        throw new IllegalStateException("The instance is not a class wrapper");
    }

    public Object setPrimitiveProperty(Object primitiveValue) {
        if (isPrimitiveType()) {
            return setProperty(PRIMITIVE_PROPERTY_VALUE, primitiveValue);
        }
        throw new IllegalStateException("The instance is not a primitive type wrapper");
    }

    public Object getPrimitiveProperty() {
        if (isPrimitiveType()) {
            return getProperty(PRIMITIVE_PROPERTY_VALUE);
        }
        throw new IllegalStateException("The instance is not a primitive type wrapper");
    }

    public Object getProperty(Object propertyName) {
        notNull(propertyName, "Property name is null");
        return properties.get(propertyName);
    }

    public boolean containsProperty(Object propertyName) {
        notNull(propertyName, "Property name is null");
        return properties.containsKey(propertyName);
    }

View on GitHub (pinned to 3a3043227f)

Solutions

  1. Construct with TYPE_PRIMITIVE: new JavaBeanDescriptor(className, JavaBeanDescriptor.TYPE_PRIMITIVE) before calling setPrimitiveProperty.
  2. Guard with if (desc.isPrimitiveType()) before calling primitive mutators.
  3. Branch on descriptor type in generic processing code.
  4. Create a new descriptor of the correct type instead of reusing one for a different kind.

Example fix

// before
JavaBeanDescriptor desc = new JavaBeanDescriptor();
desc.setPrimitiveProperty(42);  // throws, type is 0
// after
JavaBeanDescriptor desc = new JavaBeanDescriptor("int", JavaBeanDescriptor.TYPE_PRIMITIVE);
desc.setPrimitiveProperty(42);
Defensive patterns

Strategy: type-guard

Type guard

// Only set primitive value when the descriptor is actually a primitive wrapper
boolean canSetPrimitive(JavaBeanDescriptor d) {
    return d.isPrimitiveType();
}

Prevention

When it happens

Trigger: desc.setPrimitiveProperty(value) on a JavaBeanDescriptor whose type is not TYPE_PRIMITIVE (e.g. TYPE_CLASS, TYPE_ENUM, or default 0).

Common situations: 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.

Related errors


AI-assisted analysis of apache/dubbo@3a3043227f (2026-08-14). Data as JSON: /api/errors/d9d4175401cfa6c6. Report an issue: GitHub.