permissions-dispatcher/PermissionsDispatcher · error · WrongParametersException

Method '${e.simpleString()}()' must has less than or equal t

Error message

Method '${e.simpleString()}()' must has less than or equal to $numParams size parameter and type of it is supposed to be '${requiredType.simpleString()}'

What it means

Thrown by checkMethodParameters in Validators.kt:101 via WrongParametersException when the method declares more parameters than numParams allows. For annotations allowing at most one parameter, exceeding the count is rejected because the generated dispatcher can only supply a fixed number of arguments.

Source

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

        }
        // 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 ->
            if (!TYPE_UTILS.isSameType(param.asType(), requiredType)) {
                throw WrongParametersException(it, numParams, requiredType)
            }
        }
    }
}

fun <A : Annotation> checkMixPermissionType(items: List<ExecutableElement>, annotationClass: Class<A>) {
    items.forEach {
        val permissionValue = it.getAnnotation(annotationClass).permissionValue()
        if (permissionValue.size > 1) {
            if (permissionValue.contains(WRITE_SETTINGS)) {
                throw MixPermissionTypeException(it, WRITE_SETTINGS)
            } else if (permissionValue.contains(SYSTEM_ALERT_WINDOW)) {
                throw MixPermissionTypeException(it, SYSTEM_ALERT_WINDOW)

View on GitHub (pinned to 74b532bf1f)

Solutions

  1. Reduce the method to at most numParams parameters (typically one).
  2. Move extra data into class fields or a state object instead of parameters.
  3. Split the method into an annotated minimal method plus an unannotated helper taking the extra parameters.

Example fix

// before
@OnPermissionDenied
def fun onDenied(code: Int, reason: String) { }

// after
@OnPermissionDenied
def fun onDenied(code: Int) { onDeniedInternal(code, reason) }
private fun onDeniedInternal(code: Int, reason: String) { }
Defensive patterns

Strategy: validation

Validate before calling

@OnPermissionDenied
fun onDenied(code: Int) { } // at most numParams (1) parameters

Try / catch

try {
    build()
} catch (e: CompilationError) {
    logger.error("Too many parameters on permission callback", e)
}

Prevention

When it happens

Trigger: Annotated method with 2+ parameters while numParams is 1 (or 0), e.g. @OnPermissionDenied fun denied(a: Int, b: String); the check numParams < params.size fires before type checking.

Common situations: Adding extra parameters for convenience to a permission callback; merging two callbacks and keeping both parameter lists; misunderstanding the single-permission-string limit of generated methods.

Related errors


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