AlexStocks commented on code in PR #403:
URL: https://github.com/apache/dubbo-go-hessian2/pull/403#discussion_r4639292587


##########
object_test.go:
##########
@@ -1069,6 +1069,22 @@ func TestDecodeIntegerHasNull(t *testing.T) {
        testDecodeFramework(t, "customReplyTypedIntegerHasNull", &User{Id: nil})
 }
 
+type DoubleHolder struct {
+       Value    float64
+       PtrValue *float64
+}
+
+func (h *DoubleHolder) JavaClassName() string {
+       return "test.model.DoubleHolder"
+}
+
+// https://github.com/apache/dubbo-go-hessian2/issues/305
+func TestDecodeDoubleHasNull(t *testing.T) {
+       RegisterPOJO(&DoubleHolder{})
+

Review Comment:
   [P2] 期望值等于类型的零值,无法区分「null Double 归零」与「整个对象没有被解码」
   
   当前断言的期望对象 `&DoubleHolder{Value: 0, PtrValue: nil}` 与 `new(DoubleHolder)` 
完全相等,Java 侧 `customReplyTypedDoubleHasNull` 也把两个字段都写成 null。于是只要解码器对 
`test.model.DoubleHolder` 交回一个零值对象——字段被整段跳过、字段名映射不命中、或类型的 null 
值语义被忽略——断言照样成立,用例仍会通过。
   
   **参照 issue #305 的原始复现**:那份报文里除 `score=null` 之外还有 `name="DoubleWithNull"` 
这样的非空字段,正因为存在非空字段,才能区分「解码确实发生了,只有 Double 字段被置零」。本用例把两个字段全设为 null,恰好丢掉了这个区分能力。
   
   **影响**:这是本 PR 唯一的行为断言,它无法阻止 `float64`/`*float64` 字段的 null 处理再次退化。例如 
`decDouble` 再对 `0x4e` 报 `parse double wrong tag`(issue #305 的原始报错),或该字段在 
`decInstance` 里被整体跳过,本用例都不会变红。
   
   **建议**:给 `DoubleHolder` 增加一个非 null 的字符串字段(Java 侧写 
`"DoubleWithNull"`),期望值同时断言该字段等于该字符串,仅让 `Value`/`PtrValue` 
保持零值。这样「对象被真实解码」与「null Double 归零不报错」两条前提同时被固定。



-- 
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