Skip to content

IllegalStateException with @RequestParam Map<String, String> #1548

@vknaisl

Description

@vknaisl

We have troubles with the following combination:

  • @RequestParam Map<String, String> queryParams
  • an interface where the controller is defined
  • creating a link using methodOn in a different module through the exported interface

Example

Libraries versions:
Spring Boot: 2.3.11.RELEASE
Spring HATEOAS: 1.1.5.RELEASE

public interface AccountRESTInterface {

   PagedModel<EntityModel<AccountResponse>> listAccounts(@RequestParam Map<String, String> queryParams);

}
@RestController
public class AccountRESTController implements AccountRESTInterface {

  @Override
   PagedModel<EntityModel<AccountResponse>> listAccounts(@RequestParam Map<String, String> queryParams) {
       ...
  }

}
@FeignClient(...)
public interface AccountRESTClient extends AccountRESTInterface {

   PagedModel<EntityModel<AccountResponse>> listAccounts(@RequestParam Map<String, String> queryParams);

}
// Usage that interface to create a link in a different module
methodOn(AccountRESTInterface.class).listAccounts(Map.of())
Exception:
----------

Caused by: java.lang.IllegalStateException: Could not determine name of parameter method 'listAccounts' parameter 0! Make sure you compile with parameter information or explicitly define a parameter name in interface org.springframework.web.bind.annotation.RequestParam.
	at org.springframework.hateoas.server.core.WebHandler$HandlerMethodParameter.determineVariableName(WebHandler.java:454)

Solution

The solution is to change AccountRESTInterface to AccountRESTController or to explicitly name all the query parameters through request params (@RequestParam). However, we don't have an AccountRESTController in a different module since we export from our module just AccountRESTInterface to be able to create a Feign client.

We experience this issue since upgrading to Spring Boot 2.3.11.RELEASE and Spring HATEOAS 1.1.5.RELEASE. We don't have this experience with Spring Boot 2.0.4.RELEASE and Spring HATEOAS 0.25.0.RELEASE

Metadata

Metadata

Assignees

Labels

in: coreCore parts of the project

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions