permissions-dispatcher/PermissionsDispatcher · error · DuplicatedMethodNameException
'${e.simpleString()}()' has duplicated '@NeedsPermission' me
Error message
'${e.simpleString()}()' has duplicated '@NeedsPermission' method. The method annotated with '@NeedsPermission' must has the unique name. What it means
The PermissionsDispatcher processor requires every @NeedsPermission-annotated method in a class to have a unique simple name, because generated dispatcher code references these methods by name. Two annotated methods with the same name (e.g. Java overloads, or same-named methods in a class hierarchy) make the generated binding ambiguous, so compilation fails.
Source
Thrown at processor/src/main/kotlin/permissions/dispatcher/processor/util/Validators.kt:137
throw MixPermissionTypeException(it, SYSTEM_ALERT_WINDOW)
}
}
}
}
fun checkSpecialPermissionsWithNeverAskAgain(items: List<ExecutableElement>, annotationClass: Class<OnNeverAskAgain> = OnNeverAskAgain::class.java) {
items.forEach {
val permissionValue = it.getAnnotation(annotationClass).permissionValue()
if (permissionValue.contains(WRITE_SETTINGS) || permissionValue.contains(SYSTEM_ALERT_WINDOW)) {
throw SpecialPermissionsWithNeverAskAgainException()
}
}
}
fun checkDuplicatedMethodName(items: List<ExecutableElement>) {
items.forEach { item ->
items.firstOrNull { it != item && it.simpleName == item.simpleName }?.let {
throw DuplicatedMethodNameException(item)
}
}
}
View on GitHub (pinned to 74b532bf1f)
Solutions
- Rename one of the duplicated @NeedsPermission methods to a unique, descriptive name
- Merge overloads into a single annotated method with default parameters instead of multiple same-named overloads
- If the clash comes from inheritance, rename the subclass method or remove the annotation from one level
Example fix
// before
@NeedsPermission(Manifest.permission.CAMERA)
fun request() { }
@NeedsPermission(Manifest.permission.ACCESS_FINE_LOCATION)
fun request() { }
// after
@NeedsPermission(Manifest.permission.CAMERA)
fun requestCamera() { }
@NeedsPermission(Manifest.permission.ACCESS_FINE_LOCATION)
fun requestLocation() { } Defensive patterns
Strategy: validation
Validate before calling
// scan for duplicate simple names among @NeedsPermission methods before building
val annotated = listOf("requestCamera", "requestLocation") // names of @NeedsPermission methods
val duplicates = annotated.groupingBy { it }.eachCount().filterValues { it > 1 }
require(duplicates.isEmpty()) { "Duplicate @NeedsPermission method names: $duplicates" } Type guard
fun List<String>.hasUniqueNames(): Boolean = size == distinct().size
require(annotatedMethodNames.hasUniqueNames()) { "@NeedsPermission methods must have unique names" } Prevention
- Never overload @NeedsPermission-annotated methods; use unique descriptive names per permission set
- Prefer Kotlin default parameters over overloads for optional arguments on annotated methods
- When using inheritance, ensure subclass annotated methods do not reuse base-class annotated method names
When it happens
Trigger: Declaring two @NeedsPermission methods with identical simpleName in the same class (e.g. overloads fun request() and fun request(s: String)), or having a subclass and superclass both declare @NeedsPermission methods with the same simple name that the processor sees together.
Common situations: Java-style method overloading carried into Kotlin annotated methods; refactoring two features to reuse a generic name like 'request' or 'onPermission'; inheritance hierarchies where a base class's annotated method name is reused in a subclass.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- '${TypeName.get(type)}' can't be annotated with '@RuntimePer
- $value is duplicated in '${e.simpleString()}()' annotated wi
- Annotated class '${rpe.inputClassName}' doesn't have any met
- Method '${e.simpleString()}()' annotated with '@${annotation
- Method '${e.simpleString()}()' must specify return type 'voi
AI-assisted analysis of permissions-dispatcher/PermissionsDispatcher@74b532bf1f (2026-09-08).
Data as JSON: /api/errors/26933e7791b8ed08.
Report an issue: GitHub.