{"record":{"id":"d873a2d53cf4da66","repo":"permissions-dispatcher/PermissionsDispatcher","slug":"typename-get-type-can-t-be-annotated-with","errorCode":null,"errorMessage":"'${TypeName.get(type)}' can't be annotated with '@RuntimePermissions'","messagePattern":"'(.+?)' can't be annotated with '@RuntimePermissions'","errorType":"exception","errorClass":"WrongClassException","httpStatus":null,"severity":"error","filePath":"processor/src/main/kotlin/permissions/dispatcher/processor/util/Validators.kt","lineNumber":27,"sourceCode":"import javax.lang.model.element.Element\nimport javax.lang.model.element.ExecutableElement\nimport javax.lang.model.element.Modifier\nimport javax.lang.model.type.TypeKind\nimport javax.lang.model.type.TypeMirror\n\nprivate const val WRITE_SETTINGS = \"android.permission.WRITE_SETTINGS\"\nprivate const val SYSTEM_ALERT_WINDOW = \"android.permission.SYSTEM_ALERT_WINDOW\"\n\n/**\n * Obtains the [ProcessorUnit] implementation for the provided element.\n * Raises an exception if no suitable implementation exists\n */\nfun <K> findAndValidateProcessorUnit(units: List<ProcessorUnit<K>>, element: Element): ProcessorUnit<K> {\n    val type = element.asType()\n    try {\n        return units.first { type.isSubtypeOf(it.getTargetType()) }\n    } catch (ex: NoSuchElementException) {\n        throw WrongClassException(type)\n    }\n}\n\n/**\n * Checks the elements in the provided list annotated with an annotation against duplicate values.\n * <p>\n * Raises an exception if any annotation value is found multiple times.\n */\nfun <A : Annotation> checkDuplicatedValue(items: List<ExecutableElement>, annotationClass: Class<A>) {\n    val allItems: HashSet<List<String>> = hashSetOf()\n    items.forEach {\n        val permissionValue = it.getAnnotation(annotationClass).permissionValue().sorted()\n        if (allItems.contains(permissionValue)) {\n            throw DuplicatedValueException(permissionValue, it, annotationClass)\n        } else {\n            allItems.add(permissionValue)\n        }\n    }","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/permissions-dispatcher/PermissionsDispatcher/blob/74b532bf1fe430fb12ad8414b80399f2d7cfc954/processor/src/main/kotlin/permissions/dispatcher/processor/util/Validators.kt#L9-L45","documentation":"This error comes from the PermissionsDispatcher annotation processor's Validators.kt:27. The processor scans an element annotated with @RuntimePermissions (or sibling annotations) and tries to find a matching ProcessorUnit for the element's type; when no processor unit's target type is a supertype of the annotated type, it throws WrongClassException with this message. It means the annotation was placed on a kind of element the library cannot process (typically not a class, or a type the processor does not recognize).","triggerScenarios":"Placing @RuntimePermissions on a type that is not a supported class element (e.g. an interface, annotation, enum, or another annotation type), so units.first { type.isSubtypeOf(it.targetType) } finds no match and throws NoSuchElementException, converted to WrongClassException.","commonSituations":"Mistakenly annotating an interface or abstract declaration instead of an Activity/Fragment class; applying the annotation to the wrong element while refactoring; using an old processor version that does not know the new target type (e.g. newer Fragment classes); copy-pasting the annotation onto helper classes.","solutions":["Move @RuntimePermissions onto a supported class type (an Activity or Fragment class declaration, not an interface or enum).","Verify the element carrying the annotation is the class itself, not a companion object or nested type.","Update kapt/annotation-processor and library versions so the processor's target types match your class hierarchy.","Check that the class is in a module where the annotation processor is correctly configured (kapt/ksp dependencies present)."],"exampleFix":"// before\n@RuntimePermissions\ninterface MyFragmentInterface { }\n\n// after\n@RuntimePermissions\nclass MyFragment : Fragment() { }","handlingStrategy":"validation","validationCode":"val el: Element = ...\nrequire(el.kind == ElementKind.CLASS && el is TypeElement) { \"@RuntimePermissions must target a class\" }","typeGuard":"fun isValidTarget(e: Element) = e.kind == ElementKind.CLASS && e.modifiers.contains(Modifier.PUBLIC)","tryCatchPattern":null,"preventionTips":["Only annotate concrete Activity/Fragment class declarations.","Keep processor and runtime library versions in sync.","Run kapt early in CI so processor errors surface at build time."],"tags":["kotlin","annotation-processor","permissionsdispatcher"],"backgroundTag":"incompatible-source-type","analyzedSha":"74b532bf1fe430fb12ad8414b80399f2d7cfc954","analyzedAt":"2026-09-08T21:44:58.380Z","contentChangedAt":"2026-09-08T21:44:58.380Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}