diff --git a/spring-aop/src/main/java/org/springframework/aop/interceptor/AsyncExecutionInterceptor.java b/spring-aop/src/main/java/org/springframework/aop/interceptor/AsyncExecutionInterceptor.java index a17ed63fe8f..12e073db035 100644 --- a/spring-aop/src/main/java/org/springframework/aop/interceptor/AsyncExecutionInterceptor.java +++ b/spring-aop/src/main/java/org/springframework/aop/interceptor/AsyncExecutionInterceptor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 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. @@ -17,7 +17,6 @@ package org.springframework.aop.interceptor; import java.lang.reflect.Method; -import java.lang.reflect.Modifier; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.Executor; @@ -61,7 +60,6 @@ import org.springframework.lang.Nullable; * @author Juergen Hoeller * @author Chris Beams * @author Stephane Nicoll - * @author Bao Ngo * @since 3.0 * @see org.springframework.scheduling.annotation.Async * @see org.springframework.scheduling.annotation.AsyncAnnotationAdvisor @@ -127,16 +125,7 @@ public class AsyncExecutionInterceptor extends AsyncExecutionAspectSupport imple return null; }; - return doSubmit( task, executor, determineReturnType( invocation, userMethod ) ); - } - - private static Class determineReturnType(MethodInvocation invocation, Method userMethod) { - Method originalMethod = invocation.getMethod(); - if( Modifier.isAbstract( originalMethod.getModifiers() ) ) { - return userMethod.getReturnType(); - } - - return originalMethod.getReturnType(); + return doSubmit(task, executor, userMethod.getReturnType()); } /** diff --git a/spring-aop/src/test/java/org/springframework/aop/interceptor/AsyncExecutionInterceptorTests.java b/spring-aop/src/test/java/org/springframework/aop/interceptor/AsyncExecutionInterceptorTests.java index 1bb59e41865..e18f4d24b8c 100644 --- a/spring-aop/src/test/java/org/springframework/aop/interceptor/AsyncExecutionInterceptorTests.java +++ b/spring-aop/src/test/java/org/springframework/aop/interceptor/AsyncExecutionInterceptorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 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. @@ -43,32 +43,31 @@ import static org.mockito.Mockito.verify; class AsyncExecutionInterceptorTests { @Test - public void testInvokeOnInterface() throws Throwable { - AsyncExecutionInterceptor interceptor = spy( new AsyncExecutionInterceptor( null ) ); - Impl impl = new Impl(); - ArgumentCaptor> classArgumentCaptor = ArgumentCaptor.forClass( Class.class ); + @SuppressWarnings("unchecked") + void invokeOnInterfaceWithGeneric() throws Throwable { + AsyncExecutionInterceptor interceptor = spy(new AsyncExecutionInterceptor(null)); + FutureRunner impl = new FutureRunner(); MethodInvocation mi = mock(); - given( mi.getThis() ).willReturn( impl ); - given( mi.getMethod() ).willReturn( I.class.getMethod( "doSomeThing" ) ); - interceptor.invoke( mi ); - verify( interceptor ).doSubmit( - any( Callable.class ), - any( AsyncTaskExecutor.class ), - classArgumentCaptor.capture() - ); - assertThat( classArgumentCaptor.getValue() ).isEqualTo( Future.class ); + given(mi.getThis()).willReturn(impl); + given(mi.getMethod()).willReturn(GenericRunner.class.getMethod("run")); + + interceptor.invoke(mi); + ArgumentCaptor> classArgumentCaptor = ArgumentCaptor.forClass(Class.class); + verify(interceptor).doSubmit(any(Callable.class), any(AsyncTaskExecutor.class), classArgumentCaptor.capture()); + assertThat(classArgumentCaptor.getValue()).isEqualTo(Future.class); } - private interface I { - O doSomeThing(); + interface GenericRunner { + + O run(); } - private static final class Impl implements I> { + static class FutureRunner implements GenericRunner> { @Override - public Future doSomeThing() { - return CompletableFuture.runAsync( () -> { - } ); + public Future run() { + return CompletableFuture.runAsync(() -> { + }); } } }