Skip to content

Commit 9a513cf

Browse files
committed
Enforce Future/void return declaration for async methods
Closes gh-27734
1 parent 37bebea commit 9a513cf

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

spring-aop/src/main/java/org/springframework/aop/interceptor/AsyncExecutionAspectSupport.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2021 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.
@@ -286,10 +286,14 @@ else if (ListenableFuture.class.isAssignableFrom(returnType)) {
286286
else if (Future.class.isAssignableFrom(returnType)) {
287287
return executor.submit(task);
288288
}
289-
else {
289+
else if (void.class == returnType) {
290290
executor.submit(task);
291291
return null;
292292
}
293+
else {
294+
throw new IllegalArgumentException(
295+
"Invalid return type for async method (only Future and void supported): " + returnType);
296+
}
293297
}
294298

295299
/**

0 commit comments

Comments
 (0)