AlexStocks commented on issue #2517:
URL: https://github.com/apache/dubbo-go/issues/2517#issuecomment-4149621125
## Issue 分析: dubbo protocol and dubbo-go-hessian2 can not process
(*int32)(nil) corner case
### 问题根因
问题描述:`(*int32)(nil)` 这类 typed nil pointer 在 Hessian 编码时未被正确处理为 null。
**原因分析**:
在 `encode.go` 中,原有代码只检查 `v == nil`:
```go
if v == nil {
e.buffer = EncNull(e.buffer)
return nil
}
```
但对于 `(*int32)(nil)`,虽然值为 nil,但类型信息存在,导致 `v == nil` 判断为 false。
### 解决方案
已由 PR #376 和 PR #384 解决,核心修复:
```go
vVal := reflect.ValueOf(v)
if vVal.Kind() == reflect.Ptr && vVal.IsNil() {
e.buffer = EncNull(e.buffer)
return nil
}
```
### 建议
1. **合并 PR**:#376 和 #384 功能重叠,建议合并
2. **性能优化**:考虑使用类型断言替代反射以减少开销
3. **测试补充**:添加嵌套指针类型(`**int32`)的测试
---
已在相关 PR 中提交详细审查意见。
--
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]