permissions-dispatcher/PermissionsDispatcher · error · WrongReturnTypeException

Method '${e.simpleString()}()' must specify return type 'voi

Error message

Method '${e.simpleString()}()' must specify return type 'void', not '${e.returnType}'

What it means

Thrown by checkMethodSignature in Validators.kt:82 via WrongReturnTypeException. Methods annotated with @NeedsPermission or related annotations must return void (Unit in Kotlin); the generated dispatcher relies on a fire-and-forget signature and cannot handle return values.

Source

Thrown at processor/src/main/kotlin/permissions/dispatcher/processor/util/Validators.kt:82

 */
fun <A : Annotation> checkPrivateMethods(items: List<ExecutableElement>, annotationClass: Class<A>) {
    items.forEach {
        if (it.modifiers.contains(Modifier.PRIVATE)) {
            throw PrivateMethodException(it, annotationClass)
        }
    }
}

/**
 * Checks the return type of the elements in the provided list.
 * <p>
 * Raises an exception if any element specifies a return type other than 'void'.
 */
fun checkMethodSignature(items: List<ExecutableElement>) {
    items.forEach {
        // Allow 'void' return type only
        if (it.returnType.kind != TypeKind.VOID) {
            throw WrongReturnTypeException(it)
        }
        // Allow methods without 'throws' declaration only
        if (it.thrownTypes.isNotEmpty()) {
            throw NoThrowsAllowedException(it)
        }
    }
}

fun checkMethodParameters(items: List<ExecutableElement>, numParams: Int, requiredType: TypeMirror? = null) {
    items.forEach {
        val params = it.parameters
        if (numParams == 0 && params.isNotEmpty()) {
            throw NoParametersAllowedException(it)
        }
        if (requiredType == null) {
            return
        }
        if (numParams < params.size) {

View on GitHub (pinned to 74b532bf1f)

Solutions

  1. Change the return type to void (Unit in Kotlin) and store any needed result in a field or via callback.
  2. Move the annotation to a separate void method that performs the action.
  3. If a result is required, compute it inside the void method and pass it to a listener/callback.

Example fix

// before
@NeedsPermission(Manifest.permission.CAMERA)
fun showCamera(): Boolean { ... }

// after
@NeedsPermission(Manifest.permission.CAMERA)
fun showCamera() { ... }
Defensive patterns

Strategy: validation

Validate before calling

@NeedsPermission(Manifest.permission.CAMERA)
fun showCamera() { /* Unit return */ }

Try / catch

try {
    build()
} catch (e: CompilationError) {
    logger.error("Permission methods must return void/Unit", e)
}

Prevention

When it happens

Trigger: Annotated method returning a non-void type, e.g. fun showCamera(): Boolean or fun getCamera() : Camera annotated with @NeedsPermission.

Common situations: Converting an existing getter-like method into a permission-gated one; adding the annotation to a method that returns a status/result; Java methods returning boolean/int annotated for convenience.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of permissions-dispatcher/PermissionsDispatcher@74b532bf1f (2026-09-08). Data as JSON: /api/errors/25347e8b9e56ecd0. Report an issue: GitHub.