conductor-oss/conductor · error · IllegalArgumentException

cannot wrap primitive type:

Error message

cannot wrap primitive type: 

What it means

Thrown as IllegalArgumentException by WrappedType.wrap when the value type of a generic (collection/map) is not an instance of Class. protogen wraps collection element types in a generated mapper; a non-Class value type (a TypeVariable, a generic array, a primitive) has no simple name to build the wrapper class name from, so wrapping is refused.

Source

Thrown at annotations-processor/src/main/java/com/netflix/conductor/annotationsprocessor/protogen/types/WrappedType.java:30

 */
package com.netflix.conductor.annotationsprocessor.protogen.types;

import java.lang.reflect.Type;
import java.util.Set;

import javax.lang.model.element.Modifier;

import com.squareup.javapoet.MethodSpec;
import com.squareup.javapoet.TypeName;

public class WrappedType extends AbstractType {
    private AbstractType realType;
    private MessageType wrappedType;

    public static WrappedType wrap(GenericType realType) {
        Type valueType = realType.getValueType().getJavaType();
        if (!(valueType instanceof Class))
            throw new IllegalArgumentException("cannot wrap primitive type: " + valueType);

        String className = ((Class) valueType).getSimpleName() + realType.getWrapperSuffix();
        MessageType wrappedType = TypeMapper.INSTANCE.get(className);
        if (wrappedType == null)
            throw new IllegalArgumentException("missing wrapper class: " + className);
        return new WrappedType(realType, wrappedType);
    }

    public WrappedType(AbstractType realType, MessageType wrappedType) {
        super(realType.getJavaType(), wrappedType.getJavaProtoType());
        this.realType = realType;
        this.wrappedType = wrappedType;
    }

    @Override
    public String getProtoType() {
        return wrappedType.getProtoType();
    }

View on GitHub (pinned to cf7c3e4a8a)

Solutions

  1. Use a concrete element class on collection/map fields: List<String>, Map<String, Integer>, List<MyMessage>.
  2. Remove type parameters from @ProtoMessage classes that protogen must map, or bind them to concrete types.
  3. Avoid nested raw generics; flatten List<List<X>> into a wrapper message containing List<X>.

Example fix

// before
@ProtoMessage public class Container<T> {
    List<T> items; // T is a TypeVariable, not a Class
}
// after
@ProtoMessage public class Container {
    List<Item> items;
}
Defensive patterns

Strategy: type-guard

Validate before calling

import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.TypeVariable;
import java.util.Collection;
static void assertConcreteElementTypes(Class<?> msg) {
    for (Field f : msg.getDeclaredFields()) {
        if (Collection.class.isAssignableFrom(f.getType()) || Map.class.isAssignableFrom(f.getType())) {
            if (f.getGenericType() instanceof ParameterizedType pt) {
                var elem = pt.getActualTypeArguments()[pt.getActualTypeArguments().length - 1];
                if (elem instanceof TypeVariable<?>)
                    throw new IllegalStateException("Unresolved type variable on " + f + ": " + elem);
            }
        }
    }
}

Type guard

static boolean isConcreteClassType(java.lang.reflect.Type t) {
    return t instanceof Class<?>;
}

Prevention

When it happens

Trigger: A collection or map field whose generic element is itself an unresolved type variable (e.g. List<T> on a generic message), a primitive array element, or a wildcard/parameterized value type rather than a concrete class.

Common situations: Adding a generic @ProtoMessage with type parameters; nesting a parameterized type as a collection element (List<List<String>>); protogen encountering a field whose element type was not concretely resolvable.

Related errors


AI-assisted analysis of conductor-oss/conductor@cf7c3e4a8a (2026-08-14). Data as JSON: /api/errors/d45c8d0ddca0a89d. Report an issue: GitHub.