{"record":{"id":"c80dfc08962a762c","repo":"quarkusio/quarkus","slug":"unable-to-get-element-as-unwrappedtype-is-not-a-de","errorCode":null,"errorMessage":"Unable to get element as unwrappedType is not a DeclaredType: ${unwrappedType}","messagePattern":"Unable to get element as unwrappedType is not a DeclaredType: (.+?)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/discovery/ResolvedType.java","lineNumber":27,"sourceCode":"        TypeMirror unwrappedType,\n        String binaryName,\n        String qualifiedName,\n        String simplifiedName,\n        boolean isPrimitive,\n        boolean isMap,\n        boolean isList,\n        boolean isOptional,\n        boolean isSecret,\n        boolean isDeclared,\n        boolean isInterface,\n        boolean isClass,\n        boolean isEnum,\n        boolean isDuration,\n        boolean isConfigGroup) {\n\n    public TypeElement unwrappedTypeElement() {\n        if (!isDeclared) {\n            throw new IllegalStateException(\"Unable to get element as unwrappedType is not a DeclaredType: \" + unwrappedType);\n        }\n\n        return (TypeElement) ((DeclaredType) unwrappedType).asElement();\n    }\n\n    @Override\n    public final String toString() {\n        return unwrappedType.toString();\n    }\n\n    public static ResolvedType ofPrimitive(TypeMirror unwrappedType, String typeName) {\n        return new ResolvedType(unwrappedType, unwrappedType, typeName, typeName, typeName, true, false, false,\n                false, false, false, false, false, false, false, false);\n    }\n\n    public static ResolvedType ofDeclaredType(TypeMirror type, String binaryName,\n            String qualifiedName, String simpleName,\n            boolean isInterface, boolean isClass, boolean isEnum, boolean isDuration, boolean isConfigGroup) {","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/discovery/ResolvedType.java#L9-L45","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nTypeElement element = resolvedType.unwrappedTypeElement();\n// after\nif (resolvedType.isDeclared()) {\n    TypeElement element = resolvedType.unwrappedTypeElement();\n} else {\n    // handle primitive/array types without an element\n}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"public static Optional<TypeElement> typeElementOf(ResolvedType t) {\n    return t.isDeclared() ? Optional.of(t.unwrappedTypeElement()) : Optional.empty();\n}","tryCatchPattern":"try {\n    TypeElement el = resolvedType.unwrappedTypeElement();\n} catch (IllegalStateException e) {\n    // handle primitive/array ResolvedType without an element\n}","preventionTips":["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"],"tags":["annotation-processor","config","types","reflection"],"backgroundTag":"unsupported-type-cast","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}