This is an automated email from the ASF dual-hosted git repository.
Aias00 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git
The following commit(s) were added to refs/heads/master by this push:
new d7516456cc fix(sofa): handle null rpc results (#7111)
d7516456cc is described below
commit d7516456ccb62a36628c371256a05c883f993721
Author: Liming Deng <[email protected]>
AuthorDate: Tue Sep 22 21:37:19 2026 +0800
fix(sofa): handle null rpc results (#7111)
Co-authored-by: aias00 <[email protected]>
---
.../shenyu/plugin/sofa/proxy/SofaProxyService.java | 5 ++---
.../plugin/sofa/proxy/SofaProxyServiceTest.java | 24 ++++++++++++++++++++++
2 files changed, 26 insertions(+), 3 deletions(-)
diff --git
a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-sofa/src/main/java/org/apache/shenyu/plugin/sofa/proxy/SofaProxyService.java
b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-sofa/src/main/java/org/apache/shenyu/plugin/sofa/proxy/SofaProxyService.java
index 91895cc533..94a9d06f95 100644
---
a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-sofa/src/main/java/org/apache/shenyu/plugin/sofa/proxy/SofaProxyService.java
+++
b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-sofa/src/main/java/org/apache/shenyu/plugin/sofa/proxy/SofaProxyService.java
@@ -105,9 +105,8 @@ public class SofaProxyService {
if (Objects.isNull(result)) {
result = Constants.SOFA_RPC_RESULT_EMPTY;
}
-
- GenericObject genericObject = (GenericObject) result;
- exchange.getAttributes().put(Constants.RPC_RESULT,
genericObject.getFields());
+ Object rpcResult = result instanceof GenericObject ?
((GenericObject) result).getFields() : result;
+ exchange.getAttributes().put(Constants.RPC_RESULT, rpcResult);
exchange.getAttributes().put(Constants.CLIENT_RESPONSE_RESULT_TYPE,
ResultEnum.SUCCESS.getName());
return result;
})).onErrorMap(ShenyuException::new);
diff --git
a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-sofa/src/test/java/org/apache/shenyu/plugin/sofa/proxy/SofaProxyServiceTest.java
b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-sofa/src/test/java/org/apache/shenyu/plugin/sofa/proxy/SofaProxyServiceTest.java
index 218c7106c5..02f02c9019 100644
---
a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-sofa/src/test/java/org/apache/shenyu/plugin/sofa/proxy/SofaProxyServiceTest.java
+++
b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-sofa/src/test/java/org/apache/shenyu/plugin/sofa/proxy/SofaProxyServiceTest.java
@@ -45,10 +45,13 @@ import org.springframework.lang.NonNull;
import org.springframework.mock.http.server.reactive.MockServerHttpRequest;
import org.springframework.mock.web.server.MockServerWebExchange;
import org.springframework.web.server.ServerWebExchange;
+import reactor.core.publisher.Mono;
+import reactor.test.StepVerifier;
import java.lang.reflect.Field;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -149,6 +152,27 @@ public final class SofaProxyServiceTest {
RpcInvokeContext.getContext().getResponseCallback().onAppResponse("success",
null, null);
}
+ @Test
+ @SuppressWarnings("all")
+ public void testGenericInvokerWithNullResult() throws
IllegalAccessException {
+ ConsumerConfig consumerConfig = mock(ConsumerConfig.class);
+ GenericService genericService = mock(GenericService.class);
+ when(consumerConfig.refer()).thenReturn(genericService);
+ when(consumerConfig.getInterfaceId()).thenReturn(PATH);
+ when(genericService.$genericInvoke(METHOD_NAME, LEFT,
RIGHT)).thenReturn(null);
+ ApplicationConfigCache applicationConfigCache =
ApplicationConfigCache.getInstance();
+ final Field cacheField =
FieldUtils.getDeclaredField(ApplicationConfigCache.class, "cache", true);
+ assertNotNull(cacheField);
+ ((LoadingCache) cacheField.get(applicationConfigCache)).put(PATH,
consumerConfig);
+ SofaProxyService sofaProxyService = new SofaProxyService(new
SofaParamResolveServiceImpl());
+
+ Mono<Object> result = sofaProxyService.genericInvoker("", metaData,
new SelectorData(), exchange);
+
RpcInvokeContext.getContext().getResponseCallback().onAppResponse(null, null,
null);
+
+
StepVerifier.create(result).expectNext(Constants.SOFA_RPC_RESULT_EMPTY).verifyComplete();
+ assertEquals(Constants.SOFA_RPC_RESULT_EMPTY,
exchange.getAttribute(Constants.RPC_RESULT));
+ }
+
@Test
public void applicationConfigCacheTest() throws NoSuchFieldException,
IllegalAccessException {
ConfigurableApplicationContext context =
mock(ConfigurableApplicationContext.class);