Skip to content

Commit 239f384

Browse files
philwebbmhalbritter
andcommitted
Update PropertyMapper to better support nullability
Refactor `PropertyMapper` so that it no longer calls adapter or predicate methods by default when the source value is `null`. This effectively makes all default calls the same as using `alwaysWhenNotNull` in the previous generation of the code. For the limited times when you do need to deal with `null` values, the new `always()` method can be used. For example, map.from(source::method).to(destination::method); Will not call `destination.method(...)` if `source.method()` returns `null`. Where as: map.from(source::method).always().to(destination::method); Will call `destination.method(null)` if `source.method()` returns `null`. This update provides clearer semantics for the API and allows for better JSpecify nullability annotations. It has also simplified much of our existing property mapper code. Closes gh-47024 Co-authored-by: Moritz Halbritter <[email protected]>
1 parent 2d63763 commit 239f384

File tree

85 files changed

+572
-372
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+572
-372
lines changed

core/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebProperties.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -576,13 +576,10 @@ public void setSMaxAge(@Nullable Duration sMaxAge) {
576576
map.from(this::getCachePrivate).whenTrue().toCall(control::cachePrivate);
577577
map.from(this::getProxyRevalidate).whenTrue().toCall(control::proxyRevalidate);
578578
map.from(this::getStaleWhileRevalidate)
579-
.whenNonNull()
580579
.to((duration) -> control.staleWhileRevalidate(duration.getSeconds(), TimeUnit.SECONDS));
581580
map.from(this::getStaleIfError)
582-
.whenNonNull()
583581
.to((duration) -> control.staleIfError(duration.getSeconds(), TimeUnit.SECONDS));
584582
map.from(this::getSMaxAge)
585-
.whenNonNull()
586583
.to((duration) -> control.sMaxAge(duration.getSeconds(), TimeUnit.SECONDS));
587584
// check if cacheControl remained untouched
588585
if (control.getHeaderValue() == null) {

0 commit comments

Comments
 (0)