Update code regarding null-safety semantics
See gh-30083
This commit is contained in:
@@ -23,6 +23,7 @@ import java.util.concurrent.Future;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.web.context.request.NativeWebRequest;
|
||||
|
||||
/**
|
||||
@@ -40,6 +41,7 @@ class CallableInterceptorChain {
|
||||
|
||||
private int preProcessIndex = -1;
|
||||
|
||||
@Nullable
|
||||
private volatile Future<?> taskFuture;
|
||||
|
||||
|
||||
@@ -66,7 +68,7 @@ class CallableInterceptorChain {
|
||||
}
|
||||
}
|
||||
|
||||
public Object applyPostProcess(NativeWebRequest request, Callable<?> task, Object concurrentResult) {
|
||||
public Object applyPostProcess(NativeWebRequest request, Callable<?> task, @Nullable Object concurrentResult) {
|
||||
Throwable exceptionResult = null;
|
||||
for (int i = this.preProcessIndex; i >= 0; i--) {
|
||||
try {
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.springframework.web.context.request.async;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import org.springframework.core.task.AsyncTaskExecutor;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.web.context.request.NativeWebRequest;
|
||||
|
||||
/**
|
||||
@@ -104,7 +105,7 @@ public interface CallableProcessingInterceptor {
|
||||
* @throws Exception in case of errors
|
||||
*/
|
||||
default <T> void postProcess(NativeWebRequest request, Callable<T> task,
|
||||
Object concurrentResult) throws Exception {
|
||||
@Nullable Object concurrentResult) throws Exception {
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -48,6 +48,7 @@ import org.springframework.web.context.request.NativeWebRequest;
|
||||
* @author Rossen Stoyanchev
|
||||
* @author Juergen Hoeller
|
||||
* @author Rob Winch
|
||||
* @author Sam Brannen
|
||||
* @since 3.2
|
||||
* @param <T> the result type
|
||||
*/
|
||||
@@ -63,14 +64,19 @@ public class DeferredResult<T> {
|
||||
|
||||
private final Supplier<?> timeoutResult;
|
||||
|
||||
@Nullable
|
||||
private Runnable timeoutCallback;
|
||||
|
||||
@Nullable
|
||||
private Consumer<Throwable> errorCallback;
|
||||
|
||||
@Nullable
|
||||
private Runnable completionCallback;
|
||||
|
||||
@Nullable
|
||||
private DeferredResultHandler resultHandler;
|
||||
|
||||
@Nullable
|
||||
private volatile Object result = RESULT_NONE;
|
||||
|
||||
private volatile boolean expired;
|
||||
@@ -340,7 +346,7 @@ public class DeferredResult<T> {
|
||||
@FunctionalInterface
|
||||
public interface DeferredResultHandler {
|
||||
|
||||
void handleResult(Object result);
|
||||
void handleResult(@Nullable Object result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import java.util.List;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.web.context.request.NativeWebRequest;
|
||||
|
||||
/**
|
||||
@@ -57,8 +58,9 @@ class DeferredResultInterceptorChain {
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Object applyPostProcess(NativeWebRequest request, DeferredResult<?> deferredResult,
|
||||
Object concurrentResult) {
|
||||
@Nullable Object concurrentResult) {
|
||||
|
||||
try {
|
||||
for (int i = this.preProcessingIndex; i >= 0; i--) {
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.web.context.request.async;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.web.context.request.NativeWebRequest;
|
||||
|
||||
/**
|
||||
@@ -82,7 +83,7 @@ public interface DeferredResultProcessingInterceptor {
|
||||
* @throws Exception in case of errors
|
||||
*/
|
||||
default <T> void postProcess(NativeWebRequest request, DeferredResult<T> deferredResult,
|
||||
Object concurrentResult) throws Exception {
|
||||
@Nullable Object concurrentResult) throws Exception {
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -28,6 +28,7 @@ import jakarta.servlet.AsyncListener;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.web.context.request.ServletWebRequest;
|
||||
|
||||
@@ -44,10 +45,6 @@ import org.springframework.web.context.request.ServletWebRequest;
|
||||
*/
|
||||
public class StandardServletAsyncWebRequest extends ServletWebRequest implements AsyncWebRequest, AsyncListener {
|
||||
|
||||
private Long timeout;
|
||||
|
||||
private AsyncContext asyncContext;
|
||||
|
||||
private final AtomicBoolean asyncCompleted = new AtomicBoolean();
|
||||
|
||||
private final List<Runnable> timeoutHandlers = new ArrayList<>();
|
||||
@@ -56,6 +53,12 @@ public class StandardServletAsyncWebRequest extends ServletWebRequest implements
|
||||
|
||||
private final List<Runnable> completionHandlers = new ArrayList<>();
|
||||
|
||||
@Nullable
|
||||
private Long timeout;
|
||||
|
||||
@Nullable
|
||||
private AsyncContext asyncContext;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new instance for the given request/response pair.
|
||||
|
||||
@@ -52,6 +52,7 @@ import org.springframework.web.context.request.async.DeferredResult.DeferredResu
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @author Juergen Hoeller
|
||||
* @author Sam Brannen
|
||||
* @since 3.2
|
||||
* @see org.springframework.web.context.request.AsyncWebRequestInterceptor
|
||||
* @see org.springframework.web.servlet.AsyncHandlerInterceptor
|
||||
@@ -76,12 +77,15 @@ public final class WebAsyncManager {
|
||||
private static Boolean taskExecutorWarning = true;
|
||||
|
||||
|
||||
@Nullable
|
||||
private AsyncWebRequest asyncWebRequest;
|
||||
|
||||
private AsyncTaskExecutor taskExecutor = DEFAULT_TASK_EXECUTOR;
|
||||
|
||||
@Nullable
|
||||
private volatile Object concurrentResult = RESULT_NONE;
|
||||
|
||||
@Nullable
|
||||
private volatile Object[] concurrentResultContext;
|
||||
|
||||
/*
|
||||
@@ -164,6 +168,7 @@ public final class WebAsyncManager {
|
||||
* concurrent handling.
|
||||
* @see #clearConcurrentResult()
|
||||
*/
|
||||
@Nullable
|
||||
public Object[] getConcurrentResultContext() {
|
||||
return this.concurrentResultContext;
|
||||
}
|
||||
@@ -377,7 +382,7 @@ public final class WebAsyncManager {
|
||||
return request != null ? request.getRequestURI() : "servlet container";
|
||||
}
|
||||
|
||||
private void setConcurrentResultAndDispatch(Object result) {
|
||||
private void setConcurrentResultAndDispatch(@Nullable Object result) {
|
||||
synchronized (WebAsyncManager.this) {
|
||||
if (this.concurrentResult != RESULT_NONE) {
|
||||
return;
|
||||
|
||||
@@ -30,6 +30,7 @@ import org.springframework.web.context.request.NativeWebRequest;
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @author Juergen Hoeller
|
||||
* @author Sam Brannen
|
||||
* @since 3.2
|
||||
* @param <V> the value type
|
||||
*/
|
||||
@@ -37,11 +38,14 @@ public class WebAsyncTask<V> implements BeanFactoryAware {
|
||||
|
||||
private final Callable<V> callable;
|
||||
|
||||
private Long timeout;
|
||||
@Nullable
|
||||
private final Long timeout;
|
||||
|
||||
private AsyncTaskExecutor executor;
|
||||
@Nullable
|
||||
private final AsyncTaskExecutor executor;
|
||||
|
||||
private String executorName;
|
||||
@Nullable
|
||||
private final String executorName;
|
||||
|
||||
private BeanFactory beanFactory;
|
||||
|
||||
@@ -59,6 +63,9 @@ public class WebAsyncTask<V> implements BeanFactoryAware {
|
||||
public WebAsyncTask(Callable<V> callable) {
|
||||
Assert.notNull(callable, "Callable must not be null");
|
||||
this.callable = callable;
|
||||
this.timeout = null;
|
||||
this.executor = null;
|
||||
this.executorName = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -67,8 +74,11 @@ public class WebAsyncTask<V> implements BeanFactoryAware {
|
||||
* @param callable the callable for concurrent handling
|
||||
*/
|
||||
public WebAsyncTask(long timeout, Callable<V> callable) {
|
||||
this(callable);
|
||||
Assert.notNull(callable, "Callable must not be null");
|
||||
this.callable = callable;
|
||||
this.timeout = timeout;
|
||||
this.executor = null;
|
||||
this.executorName = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,10 +88,12 @@ public class WebAsyncTask<V> implements BeanFactoryAware {
|
||||
* @param callable the callable for concurrent handling
|
||||
*/
|
||||
public WebAsyncTask(@Nullable Long timeout, String executorName, Callable<V> callable) {
|
||||
this(callable);
|
||||
Assert.notNull(callable, "Callable must not be null");
|
||||
Assert.notNull(executorName, "Executor name must not be null");
|
||||
this.executorName = executorName;
|
||||
this.callable = callable;
|
||||
this.timeout = timeout;
|
||||
this.executor = null;
|
||||
this.executorName = executorName;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -91,10 +103,12 @@ public class WebAsyncTask<V> implements BeanFactoryAware {
|
||||
* @param callable the callable for concurrent handling
|
||||
*/
|
||||
public WebAsyncTask(@Nullable Long timeout, AsyncTaskExecutor executor, Callable<V> callable) {
|
||||
this(callable);
|
||||
Assert.notNull(callable, "Callable must not be null");
|
||||
Assert.notNull(executor, "Executor must not be null");
|
||||
this.executor = executor;
|
||||
this.callable = callable;
|
||||
this.timeout = timeout;
|
||||
this.executor = executor;
|
||||
this.executorName = null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user