quarkusio/quarkus · error · IllegalArgumentException

The number of parameters of method ${method} of Repository $

Error message

The number of parameters of method ${method} of Repository ${repository} does not match the number of parameter needed (inferred from the method name)

What it means

For derived query methods, the extension parses the method name (e.g. findByLastNameAndAge) to determine how many query parameters are required. If the actual number of non-Pageable/Sort/projection parameters in the signature differs from the count implied by the method name, the build fails with this error in DerivedMethodsAdder.add.

Source

Thrown at extensions/spring-data-jpa/deployment/src/main/java/io/quarkus/spring/data/deployment/generate/DerivedMethodsAdder.java:141

                                + "has invalid parameters - only a single parameter of type" + DotNames.SPRING_DATA_SORT
                                + " can be specified");
                    }
                    sortParameterIndex = i;
                } else if (isDynamicProjectionParameter(paramType, method)) {
                    if (dynamicProjectionParameterIndex != null) {
                        throw new IllegalArgumentException("Method " + method.name() + " of Repository " + repositoryClassInfo
                                + "has invalid parameters - only a single dynamic projection parameter of type "
                                + DotNames.CLASS + " can be specified");
                    }
                    dynamicProjectionParameterIndex = i;
                } else {
                    queryParameterIndexes.add(i);
                }
            }

            MethodNameParser.Result parseResult = methodNameParser.parse(method);
            if (parseResult.getParamCount() != queryParameterIndexes.size()) {
                throw new IllegalArgumentException("The number of parameters of method " + method.name() + " of Repository "
                        + repositoryClassInfo
                        + " does not match the number of parameter needed (inferred from the method name)");
            }

            // Need effectively final copies for use in lambdas
            final Integer finalPageableParameterIndex = pageableParameterIndex;
            final Integer finalSortParameterIndex = sortParameterIndex;
            final Integer finalDynamicProjectionParameterIndex = dynamicProjectionParameterIndex;
            final Type finalReturnType = returnType;

            MethodTypeDesc mtd = GenerationUtil.toMethodTypeDesc(returnType.name().toString(), parameterTypesStr);
            classCreator.method(method.name(), mc -> {
                mc.setType(mtd);

                // Add @Transactional for delete queries before calling body()
                if (parseResult.getQueryType() == MethodNameParser.QueryType.DELETE) {
                    mc.addAnnotation(Transactional.class);
                }

View on GitHub (pinned to e1c734241f)

Solutions

  1. Make the method name predicate count match the parameter count (e.g. rename findByName to findByNameAndAge or drop the extra parameter)
  2. Add the missing parameter for each condition in the method name
  3. Remove extra parameters or the corresponding condition keyword from the name
  4. Convert the method to an explicit @Query if the name-based derivation is too fragile

Example fix

// before
List<User> findByNameAndAge(String name);

// after
List<User> findByNameAndAge(String name, Integer age);
Defensive patterns

Strategy: validation

Validate before calling

// count condition keywords in the derived name (And/Or) and ensure params match
int expected = countConditions("findByNameAndAge"); // 2

Prevention

When it happens

Trigger: Method name predicates and parameter list disagree, e.g. findByName(String first, String last) or findByNameAndAge(String name) — MethodNameParser.Result.getParamCount() != queryParameterIndexes.size().

Common situations: Renaming a method to add 'AndAge' without adding the parameter; adding a parameter without updating the name; typos in property names in the method name; using Optional/wrapper mismatches that alter counting is NOT this, but plain count mismatch is.

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/1dbc45984df35915. Report an issue: GitHub.