mochengqian opened a new pull request, #3284:
URL: https://github.com/apache/dubbo-go/pull/3284

   ### Description
   Fixes  issue #3259
   **注意:本次PR为短期方案,但是已经可以关闭issue #3259**
   
   **背景**
   Java 客户端通过泛化调用(`$invoke`)访问 Go 服务端定义了变长参数(`...T`)的方法时,
     框架会触发 `reflect.Value.Call` panic,导致调用 100% 失败(测试见issue的comment)。
   
     ## 根因
   
     两层问题叠加:
   
     1. **`service_filter.go` 参数数量校验过严** — `argsType` 中变长参数被记录为单个切片类型
        (如 `[]string`),但 Java 端可能以离散形式发送多个 args,
        `len(args) != len(argsType)` 直接拒绝
     2. **`callLocalMethod` 使用 `reflect.Value.Call()`** — 即使参数数量对齐,
        已打包为切片的变长参数传入 `Call()` 时会因类型不匹配触发
        `panic: cannot use []string as type string in Call`
   
     ## 修复方案
   
     采用**统一数组传参 + CallSlice 动态类型重塑**策略,改动封锁在框架内部,
     对外部业务代码零侵入:
   
     | 文件 | 改动 |
     |------|------|
     | `common/rpc_service.go` | `MethodType` 新增 `IsVariadic()` 方法,暴露变长方法元信息 |
     | `filter/generic/service_filter.go` | 识别变长方法后,将 Java 传来的离散 args 或数组 args 
通过 `reflect.MakeSlice` 重塑为精确类型切片 |
     | `proxy/proxy_factory/utils.go` | 变长方法且尾参数为切片时使用 `CallSlice` 替代 `Call` |
     | `proxy/proxy_factory/default.go` | variadic 分支优先于 `[]interface{}` 
passthrough 检测,避免 `...interface{}` 被错误多包一层 |
   
     支持 Java 端两种传参形式:
     - **Form A(离散传参)**:`args: ["a", "b"]` — 框架自动收拢为切片
     - **Form B(数组传参)**:`args: [["a", "b"]]` — 框架自动解包内层数组
   
     
   ### 用户现在怎么调用:
   
     Java 泛化调用 Go variadic 方法,两种传参方式都支持了:
   
     **方式 A:离散传参**
     genericService.$invoke(
         "MultiArgs",
         new String[]{"java.lang.String", "java.lang.String"},
         new Object[]{"a", "b"}
     );
   
     **方式 B:数组传参(推荐)**
     genericService.$invoke(
         "MultiArgs",
         new String[]{"[Ljava.lang.String;"},
         new Object[]{new String[]{"a", "b"}}
     );
   
     **非泛化调用也正常工作,Java 端按普通方法调用即可。**
   
   ## 边界条件处理
   
     | 场景 | 行为 |
     |------|------|
     | 零变长参数(空数组/未传参数) | 构造长度为 0 的空切片,不 panic |
     | 单变长参数 | 正常投递,不误解析为多重嵌套 |
     | `...interface{}` 混合类型 | 直接接受任何值,不做强转 |
     | 固定参数 + 变长参数混合 | 固定部分走常规 Realize,尾部进入变长重塑 |
     | 显式 nil 注入 | 等同于零参数调用,不解引用 panic |
   
   ### Checklist
   - [ ] I confirm the target branch is `develop`
   - [ ] Code has passed local testing
   - [ ] I have added tests that prove my fix is effective or that my feature 
works
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to