permissions-dispatcher/PermissionsDispatcher · error · NoThrowsAllowedException

Method '${e.simpleString()}()' must not have any 'throws' de

Error message

Method '${e.simpleString()}()' must not have any 'throws' declaration in its signature

What it means

Thrown by checkMethodSignature in Validators.kt:86 via NoThrowsAllowedException. Annotated permission methods must not declare checked exceptions (throws clauses); the generated code calls these methods directly and the library does not propagate or wrap checked exceptions.

Source

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

            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) {
            throw WrongParametersException(it, numParams, requiredType)
        }
        // maximum params size is 1
        params.forEach { param ->

View on GitHub (pinned to 74b532bf1f)

Solutions

  1. Remove the throws declaration and handle exceptions inside the method with try/catch.
  2. Wrap the throwing code so no checked exception escapes the method signature.
  3. Remove @Throws in Kotlin so the generated Java signature has no throws clause.

Example fix

// before
@NeedsPermission(Manifest.permission.CAMERA)
@Throws(IOException::class)
fun showCamera() { ... }

// after
@NeedsPermission(Manifest.permission.CAMERA)
fun showCamera() {
    try { ... } catch (e: IOException) { /* handle */ }
}
Defensive patterns

Strategy: validation

Validate before calling

@NeedsPermission(Manifest.permission.CAMERA)
fun showCamera() { try { riskyIo() } catch (e: IOException) { } }

Try / catch

try {
    build()
} catch (e: CompilationError) {
    logger.error("Remove throws declarations from permission-annotated methods", e)
}

Prevention

When it happens

Trigger: Annotated method declared with a throws clause, e.g. void showCamera() throws IOException annotated with @NeedsPermission.

Common situations: Annotating an IO-heavy Java method that already throws checked exceptions; Kotlin interop with @Throws annotated functions; legacy methods retrofitted with permission annotations.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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