This is an automated email from the ASF dual-hosted git repository.
funky-eyes pushed a commit to branch 2.x
in repository https://gitbox.apache.org/repos/asf/incubator-seata.git
The following commit(s) were added to refs/heads/2.x by this push:
new 941162f663 bugfix: Avoid null advice during AOT proxy creation (#8106)
941162f663 is described below
commit 941162f66388bc09f5b69a10b0302fb8ee78c918
Author: somil jain <[email protected]>
AuthorDate: Tue May 26 15:37:30 2026 +0530
bugfix: Avoid null advice during AOT proxy creation (#8106)
---
changes/en-us/2.x.md | 1 +
.../annotation/GlobalTransactionScanner.java | 2 +-
.../annotation/GlobalTransactionScannerTest.java | 40 ++++++++++++++++------
3 files changed, 32 insertions(+), 11 deletions(-)
diff --git a/changes/en-us/2.x.md b/changes/en-us/2.x.md
index cd59b080f8..05eac4b186 100644
--- a/changes/en-us/2.x.md
+++ b/changes/en-us/2.x.md
@@ -45,6 +45,7 @@ Add changes here for all PR submitted to the 2.x branch.
- [[#7992](https://github.com/apache/incubator-seata/pull/7992)] fix report
branch transaction status without setting branch type
- [[#8035](https://github.com/apache/incubator-seata/pull/8035)] fix
IllegalArgumentException when GET request has request body
- [[#8078](https://github.com/apache/incubator-seata/pull/8078)] fix mysql
undolog NotSerializableException
+- [[#8106](https://github.com/apache/incubator-seata/pull/8106)] Avoid null
advice during AOT proxy creation
### optimize:
diff --git
a/spring/seata-spring/src/main/java/org/apache/seata/spring/annotation/GlobalTransactionScanner.java
b/spring/seata-spring/src/main/java/org/apache/seata/spring/annotation/GlobalTransactionScanner.java
index 6b907e82fd..124b953523 100644
---
a/spring/seata-spring/src/main/java/org/apache/seata/spring/annotation/GlobalTransactionScanner.java
+++
b/spring/seata-spring/src/main/java/org/apache/seata/spring/annotation/GlobalTransactionScanner.java
@@ -518,7 +518,7 @@ public class GlobalTransactionScanner extends
AbstractAutoProxyCreator
@Override
protected Object[] getAdvicesAndAdvisorsForBean(Class beanClass, String
beanName, TargetSource customTargetSource)
throws BeansException {
- return new Object[] {interceptor};
+ return interceptor == null ? DO_NOT_PROXY : new Object[] {interceptor};
}
@Override
diff --git
a/spring/seata-spring/src/test/java/org/apache/seata/spring/annotation/GlobalTransactionScannerTest.java
b/spring/seata-spring/src/test/java/org/apache/seata/spring/annotation/GlobalTransactionScannerTest.java
index 5da4a2c5e5..6e8f756e38 100644
---
a/spring/seata-spring/src/test/java/org/apache/seata/spring/annotation/GlobalTransactionScannerTest.java
+++
b/spring/seata-spring/src/test/java/org/apache/seata/spring/annotation/GlobalTransactionScannerTest.java
@@ -17,6 +17,7 @@
package org.apache.seata.spring.annotation;
import org.aopalliance.aop.Advice;
+import org.aopalliance.intercept.MethodInterceptor;
import org.apache.seata.config.ConfigurationChangeEvent;
import org.apache.seata.core.constants.ConfigurationKeys;
import org.apache.seata.core.rpc.netty.RmNettyRemotingClient;
@@ -36,11 +37,15 @@ import
org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
+import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.atLeastOnce;
@@ -280,16 +285,6 @@ class GlobalTransactionScannerTest {
Assertions.assertEquals(factoryBean, result);
}
- @Test
- void testGetAdvicesAndAdvisorsForBean() {
- // Test getAdvicesAndAdvisorsForBean method
- GlobalTransactionScanner scanner = new
GlobalTransactionScanner("test-app", "test-tx-group");
-
- Object[] result =
scanner.getAdvicesAndAdvisorsForBean(TestService.class, "testService", null);
-
- Assertions.assertNotNull(result);
- }
-
@Test
void testOnChangeEventDisableGlobalTransaction() {
// Test configuration change event handling
@@ -916,4 +911,29 @@ class GlobalTransactionScannerTest {
Assertions.assertNotNull(result);
}
+
+ @Test
+ void testGetAdvicesAndAdvisorsForBeanWithNullInterceptor() {
+ GlobalTransactionScanner scanner = new
GlobalTransactionScanner("test-app", "test-tx-group");
+
+ Object[] result =
scanner.getAdvicesAndAdvisorsForBean(TestService.class, "testService", null);
+
+ assertNull(result, "Should return DO_NOT_PROXY (null) when interceptor
is not initialized");
+ }
+
+ @Test
+ void testGetAdvicesAndAdvisorsForBeanWithInitializedInterceptor() throws
Exception {
+ GlobalTransactionScanner scanner = new
GlobalTransactionScanner("test-app", "test-tx-group");
+
+ Field interceptorField =
GlobalTransactionScanner.class.getDeclaredField("interceptor");
+ interceptorField.setAccessible(true);
+ MethodInterceptor mockInterceptor = mock(MethodInterceptor.class);
+ interceptorField.set(scanner, mockInterceptor);
+
+ Object[] result =
scanner.getAdvicesAndAdvisorsForBean(TestService.class, "testService", null);
+
+ assertNotNull(result, "Should not return null when interceptor is
initialized");
+ assertEquals(1, result.length, "Should return an array of length 1");
+ assertEquals(mockInterceptor, result[0], "The array should contain the
injected interceptor");
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]