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
- Check ResolvedType.isDeclared() before calling unwrappedTypeElement()
- Handle primitives/arrays with dedicated branches instead of requesting the TypeElement
- Fix the discovery visitor to not record non-declared types as requiring element access
- 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
- Always check ResolvedType.isDeclared() before unwrapping
- Handle primitives and arrays in separate code paths when visiting config types
- Test discovery against config groups containing primitive, array, and optional types
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
- Failed to set dev services config
- Failed to set dev services override config
- Starting with Quarkus 3.25, legacy config classes (deprecate
- Two config roots with different extensions or prefixes canno
- Either @ConfigRoot or @ConfigMapping is missing on ${configR
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/c80dfc08962a762c.
Report an issue: GitHub.