Skip to content

Commit e2a5cfb

Browse files
committed
Consistent nullability for concurrent result
(cherry picked from commit b928779)
1 parent b484ab1 commit e2a5cfb

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

spring-web/src/main/java/org/springframework/web/context/request/async/WebAsyncManager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -159,6 +159,7 @@ public boolean hasConcurrentResult() {
159159
* concurrent handling raised one.
160160
* @see #clearConcurrentResult()
161161
*/
162+
@Nullable
162163
public Object getConcurrentResult() {
163164
return this.concurrentResult;
164165
}

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapter.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -48,6 +48,7 @@
4848
import org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter;
4949
import org.springframework.lang.Nullable;
5050
import org.springframework.ui.ModelMap;
51+
import org.springframework.util.Assert;
5152
import org.springframework.util.CollectionUtils;
5253
import org.springframework.util.ReflectionUtils.MethodFilter;
5354
import org.springframework.web.accept.ContentNegotiationManager;
@@ -872,7 +873,9 @@ protected ModelAndView invokeHandlerMethod(HttpServletRequest request,
872873

873874
if (asyncManager.hasConcurrentResult()) {
874875
Object result = asyncManager.getConcurrentResult();
875-
mavContainer = (ModelAndViewContainer) asyncManager.getConcurrentResultContext()[0];
876+
Object[] resultContext = asyncManager.getConcurrentResultContext();
877+
Assert.state(resultContext != null && resultContext.length > 0, "Missing result context");
878+
mavContainer = (ModelAndViewContainer) resultContext[0];
876879
asyncManager.clearConcurrentResult();
877880
LogFormatUtils.traceDebug(logger, traceOn -> {
878881
String formatted = LogFormatUtils.formatValue(result, !traceOn);

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletInvocableHandlerMethod.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -200,7 +200,7 @@ private String formatErrorForReturnValue(@Nullable Object returnValue) {
200200
* actually invoking the controller method. This is useful when processing
201201
* async return values (e.g. Callable, DeferredResult, ListenableFuture).
202202
*/
203-
ServletInvocableHandlerMethod wrapConcurrentResult(Object result) {
203+
ServletInvocableHandlerMethod wrapConcurrentResult(@Nullable Object result) {
204204
return new ConcurrentResultHandlerMethod(result, new ConcurrentResultMethodParameter(result));
205205
}
206206

@@ -215,7 +215,7 @@ private class ConcurrentResultHandlerMethod extends ServletInvocableHandlerMetho
215215

216216
private final MethodParameter returnType;
217217

218-
public ConcurrentResultHandlerMethod(final Object result, ConcurrentResultMethodParameter returnType) {
218+
public ConcurrentResultHandlerMethod(@Nullable Object result, ConcurrentResultMethodParameter returnType) {
219219
super((Callable<Object>) () -> {
220220
if (result instanceof Exception exception) {
221221
throw exception;
@@ -279,7 +279,7 @@ private class ConcurrentResultMethodParameter extends HandlerMethodParameter {
279279

280280
private final ResolvableType returnType;
281281

282-
public ConcurrentResultMethodParameter(Object returnValue) {
282+
public ConcurrentResultMethodParameter(@Nullable Object returnValue) {
283283
super(-1);
284284
this.returnValue = returnValue;
285285
this.returnType = (returnValue instanceof CollectedValuesList cvList ?

0 commit comments

Comments
 (0)