Skip to content

ObjectToOptionalConverter should use Optional.ofNullable(…) instead of Optional.of(…) [SPR-12589] #17190

@spring-projects-issues

Description

@spring-projects-issues

Oliver Drotbohm opened SPR-12589 and commented

In case the ConversionService used in the ObjectToOptionalConverter is a FormattingConversionService, a ParserConverter will be used for the String to object conversion. For empty String instances this will immediately return null from convert(…) which then causes an exception as the ObjectToOptionalConverter passes it to Optional.of(…).

Here's a sample scenario:

String someMethod(@RequestParam Optional<Point> location) { … }

Now imagine we have a Formatter registered to turn a request parameter String into a Point. If now a request ?location= (no value) is triggered, the scenario described above kicks in.


Affects: 4.1.4

Referenced from: commits ed665a1, ec84fa6

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)in: webIssues in web modules (web, webmvc, webflux, websocket)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions