apache/dubbo · warning · IllegalStateException

The instance is not a class wrapper

Error message

The instance is not a class wrapper

What it means

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.

Source

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

            return result == null ? null : result.toString();
        }
        throw new IllegalStateException("The instance is not a enum wrapper");
    }

    public String getEnumPropertyName() {
        if (isEnumType()) {
            Object result = getProperty(ENUM_PROPERTY_NAME);
            return result == null ? null : result.toString();
        }
        throw new IllegalStateException("The instance is not a enum wrapper");
    }

    public String setClassNameProperty(String name) {
        if (isClassType()) {
            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() {

View on GitHub (pinned to 3a3043227f)

Solutions

  1. Construct the descriptor as a class: new JavaBeanDescriptor(className, JavaBeanDescriptor.TYPE_CLASS) before calling setClassNameProperty.
  2. Guard with if (desc.isClassType()) before calling class mutators.
  3. Branch on descriptor type in generic processing code.
  4. Create a new descriptor of the correct type instead of reusing an existing one for a different kind.

Example fix

// before
JavaBeanDescriptor desc = new JavaBeanDescriptor();
desc.setClassNameProperty("com.foo.Bar");  // throws, type is 0
// after
JavaBeanDescriptor desc = new JavaBeanDescriptor("com.foo.Bar", JavaBeanDescriptor.TYPE_CLASS);
desc.setClassNameProperty("com.foo.Bar");
Defensive patterns

Strategy: type-guard

Type guard

// Only set class name when the descriptor is actually a class wrapper
boolean canSetClassName(JavaBeanDescriptor d) {
    return d.isClassType();
}

Prevention

When it happens

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

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

Related errors


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