spring-projects / spring-projects/spring-hateoas

RepresentationModelProcessor nullpointer having mandatory field in controller spring 2.7.4

Open
#1,872 2 comments 0 reactions 1 assignee View on GitHub

@odrotbohm is already working on this.

Since Jan 12, 2023.

in: core process: waiting for feedback
Dominant language
Java
Stars
1.1k
Forks
476
PR merge metrics
No merged PRs in 30d

Description

Hello,

I have a ResourceProcessor that's adding links to a resource:

linkTo(methodOn(MyController.class)
  .findMyElements(file.getId(), null, null))
  .withRel("filterFiles"))

The controller looks like this:

@RequestMapping(method = { POST, GET }, value = "/myFiles/{fileId}/filterFiles")
  public List<FileDto> findFilterFiles(
      @PathVariable("fileId") final Long fileId,
      @RequestParam(name = "fileType") final Long fileType,
      @RequestBody(required = false) final FileFilterDto filter) { … }

In Spring 2.6.4, it used to work. Now, I've tried upgrading to 2.7.4, and it does not work anymore. I've tracked the issue down, and it seems like the required request parameter must not be null anymore.

I'm getting a null pointer exception with text like this:
Illegal character in query at index 93: http://localhost:8080/files/10013/filterFiles?fileType={fileType}
with the index pointing to '=' of fileType={fileType} .

Is it a bug? If yes - how can I fix it? Passing a constant number fixes the null-pointer exception:

linkTo(methodOn(MyController.class)
  .findMyElements(file.getId(), 1L, null))
  .withRel("filterFiles"))

but it leads to incorrect code.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.