permissions-dispatcher/PermissionsDispatcher · error · PrivateMethodException

Method '${e.simpleString()}()' annotated with '@${annotation

Error message

Method '${e.simpleString()}()' annotated with '@${annotationType.simpleName}' must not be private

What it means

Thrown by checkPrivateMethods in Validators.kt:68. Methods annotated with permission annotations (@NeedsPermission, @OnPermissionDenied, etc.) must not be private, because the generated PermissionsDispatcher class needs to invoke them via generated delegate methods; a private method would be uncallable from the generated code.

Source

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

 * <p>
 * Raises an exception if it doesn't contain any elements.
 */
fun <A : Annotation> checkNotEmpty(items: List<ExecutableElement>, rpe: RuntimePermissionsElement, annotationClass: Class<A>) {
    if (items.isEmpty()) {
        throw NoAnnotatedMethodsException(rpe, annotationClass)
    }
}

/**
 * Checks the elements in the provided list annotated with an annotation
 * against private modifiers.
 * <p>
 * Raises an exception if any element contains the "private" modifier.
 */
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)

View on GitHub (pinned to 74b532bf1f)

Solutions

  1. Remove the private modifier so the method has at least internal/public visibility.
  2. Use internal instead of private in Kotlin if you want module-level visibility.

Example fix

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

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

Strategy: validation

Validate before calling

@NeedsPermission(Manifest.permission.CAMERA)
fun showCamera() { } // ensure no 'private' modifier

Try / catch

try {
    build()
} catch (e: CompilationError) {
    logger.error("Permission-annotated methods must not be private", e)
}

Prevention

When it happens

Trigger: Declaring an annotated method with the private modifier in Kotlin or Java, e.g. private fun showCamera() with @NeedsPermission.

Common situations: Kotlin defaulting visibility habits; making a permission callback private after a refactor; IDE auto-completion suggesting a private helper annotated by mistake.

Understand the failure class

Background: "You do not have permission" / 403 Forbidden errors: authenticated but not allowed — causes and fixes across open-source libraries — this error's family across 31 libraries.

Related errors


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