Skip to content

Commit

Permalink
Consistent nullability for concurrent result
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoeller committed Jan 24, 2024
1 parent d7778c0 commit b928779
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ public boolean hasConcurrentResult() {
* concurrent handling raised one.
* @see #clearConcurrentResult()
*/
@Nullable
public Object getConcurrentResult() {
return this.concurrentResult;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -50,6 +50,7 @@
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.ClassUtils;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ReflectionUtils.MethodFilter;
Expand Down Expand Up @@ -905,7 +906,9 @@ protected ModelAndView invokeHandlerMethod(HttpServletRequest request,

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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -200,7 +200,7 @@ private String formatErrorForReturnValue(@Nullable Object returnValue) {
* 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));
}

Expand All @@ -215,7 +215,7 @@ private class ConcurrentResultHandlerMethod extends ServletInvocableHandlerMetho

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;
Expand Down Expand Up @@ -279,7 +279,7 @@ private class ConcurrentResultMethodParameter extends AnnotatedMethodParameter {

private final ResolvableType returnType;

public ConcurrentResultMethodParameter(Object returnValue) {
public ConcurrentResultMethodParameter(@Nullable Object returnValue) {
super(-1);
this.returnValue = returnValue;
this.returnType = (returnValue instanceof CollectedValuesList cvList ?
Expand Down

0 comments on commit b928779

Please sign in to comment.