Affects: \5.1.6 I have the following code

@GetMapping("/somepath")
public String getNextDayOfMonth(
    @RequestParam(value = "target_date", required = true)
    @DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
    LocalDate targetDate
) {
    return targetDate.plusDays(1).getDayOfMonth();
}

But when I execute this handler with path like /sompath?target_date=, I get NullPointerException, because my variable target_date is null, but I define required=true and DateTimeFormat annotation. I thought, if I set DateTimeFormat property and execute this mapping with invalid date string (empty in my case), I will get client exception (4xx codes) instead of server exception (5xx, cause NPE it is server side exception).

I'm suspect, that problem in this line of code: https://github.com/spring-projects/spring-framework/blob/d05803aa04383a3b4b2dc1db2591f9fec1a156a2/spring-context/src/main/java/org/springframework/format/support/FormattingConversionService.java#L211-L214

and think, that passing empty string for date - it's client error


Comment From: ganeshbch

I think the Null pointer Exception even though required is true and the client exception is because of the handler path.

The handler path mentioned is /sompath?target_date= But the code has a handler called @GetMapping("/somepath")

The handler path has a typo and should be /somepath?target_date= instead of /sompath?target_date=

Please notice the missing 'e' in handler path. Hope this solves the issue.

Comment From: sbrannen

I'm closing this issue since it is effectively a duplicate of #23939.