Skip to content

Commit f135a2d

Browse files
committed
Add more nullability annotations to core/spring-boot
See gh-46587
1 parent 06e9827 commit f135a2d

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

core/spring-boot/src/main/java/org/springframework/boot/json/JsonValueWriter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,8 @@ private String processName(String name, NameProcessor nameProcessor) {
346346
return value;
347347
}
348348

349-
@SuppressWarnings({ "unchecked" })
349+
// Lambda isn't detected with the correct nullability
350+
@SuppressWarnings({ "unchecked", "NullAway" })
350351
private <V> @Nullable V processValue(@Nullable V value, ValueProcessor<?> valueProcessor) {
351352
return (V) LambdaSafe.callback(ValueProcessor.class, valueProcessor, this.path, new Object[] { value })
352353
.invokeAnd((call) -> call.processValue(this.path, value))

core/spring-boot/src/main/java/org/springframework/boot/util/LambdaSafe.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public SELF withFilter(Filter<C, A> filter) {
155155
return self();
156156
}
157157

158-
protected final <R> InvocationResult<R> invoke(C callbackInstance, Supplier<R> supplier) {
158+
protected final <R> InvocationResult<R> invoke(C callbackInstance, Supplier<@Nullable R> supplier) {
159159
if (this.filter.match(this.callbackType, callbackInstance, this.argument, this.additionalArguments)) {
160160
try {
161161
return InvocationResult.of(supplier.get());
@@ -245,6 +245,8 @@ private Callback(Class<C> callbackType, C callbackInstance, A argument,
245245
* Invoke the callback instance where the callback method returns void.
246246
* @param invoker the invoker used to invoke the callback
247247
*/
248+
// Lambda isn't detected with the correct nullability
249+
@SuppressWarnings("NullAway")
248250
public void invoke(Consumer<C> invoker) {
249251
invoke(this.callbackInstance, () -> {
250252
invoker.accept(this.callbackInstance);
@@ -259,7 +261,9 @@ public void invoke(Consumer<C> invoker) {
259261
* @return the result of the invocation (may be {@link InvocationResult#noResult}
260262
* if the callback was not invoked)
261263
*/
262-
public <R> InvocationResult<R> invokeAnd(Function<C, R> invoker) {
264+
// Lambda isn't detected with the correct nullability
265+
@SuppressWarnings("NullAway")
266+
public <R> InvocationResult<R> invokeAnd(Function<C, @Nullable R> invoker) {
263267
return invoke(this.callbackInstance, () -> invoker.apply(this.callbackInstance));
264268
}
265269

@@ -285,6 +289,8 @@ private Callbacks(Class<C> callbackType, Collection<? extends C> callbackInstanc
285289
* Invoke the callback instances where the callback method returns void.
286290
* @param invoker the invoker used to invoke the callback
287291
*/
292+
// Lambda isn't detected with the correct nullability
293+
@SuppressWarnings("NullAway")
288294
public void invoke(Consumer<C> invoker) {
289295
this.callbackInstances.forEach((callbackInstance) -> invoke(callbackInstance, () -> {
290296
invoker.accept(callbackInstance);
@@ -299,7 +305,9 @@ public void invoke(Consumer<C> invoker) {
299305
* @return the results of the invocation (may be an empty stream if no callbacks
300306
* could be called)
301307
*/
302-
public <R> Stream<R> invokeAnd(Function<C, R> invoker) {
308+
// Lambda isn't detected with the correct nullability
309+
@SuppressWarnings("NullAway")
310+
public <R> Stream<R> invokeAnd(Function<C, @Nullable R> invoker) {
303311
Function<C, InvocationResult<R>> mapper = (callbackInstance) -> invoke(callbackInstance,
304312
() -> invoker.apply(callbackInstance));
305313
return this.callbackInstances.stream()

0 commit comments

Comments
 (0)