Apply additional 'instanceof pattern matching' in spring-web

See gh-29530
This commit is contained in:
Sam Brannen
2022-11-21 14:28:30 +01:00
parent 50109dd86d
commit 0c878d2d06
6 changed files with 20 additions and 19 deletions

View File

@@ -129,17 +129,18 @@ public class HandlerMethodReturnValueHandlerComposite implements AsyncHandlerMet
@Override
public boolean isAsyncReturnValue(Object returnValue, MethodParameter returnType) {
HandlerMethodReturnValueHandler handler = getReturnValueHandler(returnType);
return (handler instanceof AsyncHandlerMethodReturnValueHandler &&
((AsyncHandlerMethodReturnValueHandler) handler).isAsyncReturnValue(returnValue, returnType));
return (handler instanceof AsyncHandlerMethodReturnValueHandler asyncHandler &&
asyncHandler.isAsyncReturnValue(returnValue, returnType));
}
@Override
@Nullable
public CompletableFuture<?> toCompletableFuture(Object returnValue, MethodParameter returnType) {
HandlerMethodReturnValueHandler handler = getReturnValueHandler(returnType);
if (handler instanceof AsyncHandlerMethodReturnValueHandler) {
return ((AsyncHandlerMethodReturnValueHandler) handler).toCompletableFuture(returnValue, returnType);
if (handler instanceof AsyncHandlerMethodReturnValueHandler asyncHandler) {
return asyncHandler.toCompletableFuture(returnValue, returnType);
}
return null;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -343,8 +343,8 @@ class ChannelSendOperator<T> extends Mono<Void> implements Scannable {
private void releaseCachedItem() {
synchronized (this) {
Object item = this.item;
if (item instanceof DataBuffer) {
DataBufferUtils.release((DataBuffer) item);
if (item instanceof DataBuffer dataBuffer) {
DataBufferUtils.release(dataBuffer);
}
this.item = null;
}