Browse Source

Consistent nullability for concurrent result

(cherry picked from commit b92877990d)
pull/32145/head
Juergen Hoeller 2 years ago
parent
commit
e2a5cfb459
  1. 3
      spring-web/src/main/java/org/springframework/web/context/request/async/WebAsyncManager.java
  2. 7
      spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapter.java
  3. 8
      spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletInvocableHandlerMethod.java

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

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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.
@ -159,6 +159,7 @@ public final class WebAsyncManager { @@ -159,6 +159,7 @@ public final class WebAsyncManager {
* concurrent handling raised one.
* @see #clearConcurrentResult()
*/
@Nullable
public Object getConcurrentResult() {
return this.concurrentResult;
}

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

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2024 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.
@ -48,6 +48,7 @@ import org.springframework.http.converter.StringHttpMessageConverter; @@ -48,6 +48,7 @@ import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter;
import org.springframework.lang.Nullable;
import org.springframework.ui.ModelMap;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ReflectionUtils.MethodFilter;
import org.springframework.web.accept.ContentNegotiationManager;
@ -872,7 +873,9 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter @@ -872,7 +873,9 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter
if (asyncManager.hasConcurrentResult()) {
Object result = asyncManager.getConcurrentResult();
mavContainer = (ModelAndViewContainer) asyncManager.getConcurrentResultContext()[0];
Object[] resultContext = asyncManager.getConcurrentResultContext();
Assert.state(resultContext != null && resultContext.length > 0, "Missing result context");
mavContainer = (ModelAndViewContainer) resultContext[0];
asyncManager.clearConcurrentResult();
LogFormatUtils.traceDebug(logger, traceOn -> {
String formatted = LogFormatUtils.formatValue(result, !traceOn);

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

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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.
@ -200,7 +200,7 @@ public class ServletInvocableHandlerMethod extends InvocableHandlerMethod { @@ -200,7 +200,7 @@ public class ServletInvocableHandlerMethod extends InvocableHandlerMethod {
* actually invoking the controller method. This is useful when processing
* async return values (e.g. Callable, DeferredResult, ListenableFuture).
*/
ServletInvocableHandlerMethod wrapConcurrentResult(Object result) {
ServletInvocableHandlerMethod wrapConcurrentResult(@Nullable Object result) {
return new ConcurrentResultHandlerMethod(result, new ConcurrentResultMethodParameter(result));
}
@ -215,7 +215,7 @@ public class ServletInvocableHandlerMethod extends InvocableHandlerMethod { @@ -215,7 +215,7 @@ public class ServletInvocableHandlerMethod extends InvocableHandlerMethod {
private final MethodParameter returnType;
public ConcurrentResultHandlerMethod(final Object result, ConcurrentResultMethodParameter returnType) {
public ConcurrentResultHandlerMethod(@Nullable Object result, ConcurrentResultMethodParameter returnType) {
super((Callable<Object>) () -> {
if (result instanceof Exception exception) {
throw exception;
@ -279,7 +279,7 @@ public class ServletInvocableHandlerMethod extends InvocableHandlerMethod { @@ -279,7 +279,7 @@ public class ServletInvocableHandlerMethod extends InvocableHandlerMethod {
private final ResolvableType returnType;
public ConcurrentResultMethodParameter(Object returnValue) {
public ConcurrentResultMethodParameter(@Nullable Object returnValue) {
super(-1);
this.returnValue = returnValue;
this.returnType = (returnValue instanceof CollectedValuesList cvList ?

Loading…
Cancel
Save