quarkusio/quarkus · error · IllegalStateException

Unable to get element as unwrappedType is not a DeclaredType

Error message

Unable to get element as unwrappedType is not a DeclaredType: ${unwrappedType}

What it means

ResolvedType.unwrappedTypeElement() casts the wrapped javax.lang.model type to a DeclaredType to obtain its TypeElement. It throws IllegalStateException when the resolved type was not produced from a DeclaredType (isDeclared=false), e.g. a primitive or array type.

Source

Thrown at core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/discovery/ResolvedType.java:27

        TypeMirror unwrappedType,
        String binaryName,
        String qualifiedName,
        String simplifiedName,
        boolean isPrimitive,
        boolean isMap,
        boolean isList,
        boolean isOptional,
        boolean isSecret,
        boolean isDeclared,
        boolean isInterface,
        boolean isClass,
        boolean isEnum,
        boolean isDuration,
        boolean isConfigGroup) {

    public TypeElement unwrappedTypeElement() {
        if (!isDeclared) {
            throw new IllegalStateException("Unable to get element as unwrappedType is not a DeclaredType: " + unwrappedType);
        }

        return (TypeElement) ((DeclaredType) unwrappedType).asElement();
    }

    @Override
    public final String toString() {
        return unwrappedType.toString();
    }

    public static ResolvedType ofPrimitive(TypeMirror unwrappedType, String typeName) {
        return new ResolvedType(unwrappedType, unwrappedType, typeName, typeName, typeName, true, false, false,
                false, false, false, false, false, false, false, false);
    }

    public static ResolvedType ofDeclaredType(TypeMirror type, String binaryName,
            String qualifiedName, String simpleName,
            boolean isInterface, boolean isClass, boolean isEnum, boolean isDuration, boolean isConfigGroup) {

View on GitHub (pinned to e1c734241f)

Solutions

  1. Check ResolvedType.isDeclared() before calling unwrappedTypeElement()
  2. Handle primitives/arrays with dedicated branches instead of requesting the TypeElement
  3. Fix the discovery visitor to not record non-declared types as requiring element access
  4. Upgrade Quarkus — newer processors guard this path better

Example fix

// before
TypeElement element = resolvedType.unwrappedTypeElement();
// after
if (resolvedType.isDeclared()) {
    TypeElement element = resolvedType.unwrappedTypeElement();
} else {
    // handle primitive/array types without an element
}
Defensive patterns

Strategy: type-guard

Type guard

public static Optional<TypeElement> typeElementOf(ResolvedType t) {
    return t.isDeclared() ? Optional.of(t.unwrappedTypeElement()) : Optional.empty();
}

Try / catch

try {
    TypeElement el = resolvedType.unwrappedTypeElement();
} catch (IllegalStateException e) {
    // handle primitive/array ResolvedType without an element
}

Prevention

When it happens

Trigger: Calling unwrappedTypeElement() on a ResolvedType built from a non-declared MirrorType — primitives (int, boolean), arrays, or wildcard/type-variable types — typically when walking discovered config property types in a discovery visitor.

Common situations: A config property of primitive or array type (e.g. int port or String[] hosts) whose ResolvedType is inspected with unwrappedTypeElement(); custom processor extensions mishandling non-class types.

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/c80dfc08962a762c. Report an issue: GitHub.