Skip to content

Commit 3b2a36b

Browse files
authored
AOP: Fix delegated method invocation (#11702)
1 parent 5770f69 commit 3b2a36b

File tree

4 files changed

+55
-1
lines changed

4 files changed

+55
-1
lines changed

core-processor/src/main/java/io/micronaut/aop/writer/AopProxyWriter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ public void visitAroundMethod(TypedElement beanType,
655655

656656
if (!methodElementKey.equals(overriddenByKey)) {
657657
proxyBuilder.addMethod(MethodDef.override(methodElement)
658-
.build((aThis, methodParameters) -> aThis.superRef().invoke(overriddenBy, methodParameters).returning())
658+
.build((aThis, methodParameters) -> aThis.invoke(overriddenBy, methodParameters).returning())
659659
);
660660
return;
661661
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright 2017-2020 original authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.micronaut.aop.introduction;
17+
18+
@Tx
19+
@RepoDef
20+
public interface MyRepo6 extends DeleteByIdCrudRepo<Integer> {
21+
22+
@Override
23+
void deleteById(Integer integer);
24+
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package io.micronaut.aop.introduction;
2+
3+
import jakarta.inject.Singleton;
4+
5+
@Singleton
6+
public class MyRepo6Service {
7+
8+
private final DeleteByIdCrudRepo rawRepository;
9+
10+
public MyRepo6Service(MyRepo6 myRepo6) {
11+
this.rawRepository = myRepo6;
12+
}
13+
14+
void deleteById(Integer integer) {
15+
rawRepository.deleteById(integer);
16+
}
17+
}

inject-java/src/test/groovy/io/micronaut/aop/introduction/MyRepoIntroductionSpec.groovy

+12
Original file line numberDiff line numberDiff line change
@@ -182,4 +182,16 @@ class MyRepoIntroductionSpec extends Specification {
182182
TxInterceptor.EXECUTED_METHODS.clear()
183183
}
184184

185+
void "test delegating methods"() {
186+
given:
187+
def myRepoService = applicationContext.getBean(MyRepo6Service)
188+
when:
189+
myRepoService.deleteById(1)
190+
then:
191+
MyRepoIntroducer.EXECUTED_METHODS.size() == 1
192+
MyRepoIntroducer.EXECUTED_METHODS.clear()
193+
TxInterceptor.EXECUTED_METHODS.size() == 1
194+
TxInterceptor.EXECUTED_METHODS.clear()
195+
}
196+
185197
}

0 commit comments

Comments
 (0)