apache / dubbo-go-hessian2

caucho hessian2 implementation in Go for [apache/dubbo-go](https://github.com/apache/dubbo-go) which is compatible with [dubbo-hessian-lite](https://github.com/apache/dubbo-hessian-lite)
Apache License 2.0
209 stars 113 forks source link

dubbogo-hessian2 can not unmarshal the object while it contains too many map-object which are initialized as nil #215

Closed xc19950304 closed 4 years ago

xc19950304 commented 4 years ago

本地测试发现,当对象包含多个map对象时(>=2),有两个及以上被初始化为nil时,无法反序列化,且报错“decInstance->decMapByValue field name: cookies2: illegal ref index“(eg:使用dubbogo序列化后再反序列化)

type Circular struct {
    Num      int
    Previous *Circular
    Next     *Circular
    ResponseDataBytes    []byte
    Cookies             map[string]string
    Headers            map[string]string
    Cookies2             map[string]string
    LoginResponseSession map[string]string
}

func (Circular) JavaClassName() string {
    return "com.company.Circular"
}

func main() {
    c := &Circular{}
    c.Num = 12345
    c.Previous = c
    c.Next = c
    c.Cookies = map[string]string{}
    c.Headers = nil
    c.Cookies2 =  map[string]string{}
    c.LoginResponseSession = nil

    e := hessian.NewEncoder()
    err := e.Encode(c)
    if err != nil {
        panic(err)
    }

    bytes := e.Buffer()

    decoder := hessian.NewDecoder(bytes)

    decode, err := decoder.Decode()

    if err != nil {
        panic(err)
    }

    fmt.Println(decode)
}
wongoo commented 4 years ago

this issue will be fixed by https://github.com/apache/dubbo-go-hessian2/pull/216

wongoo commented 4 years ago

@xc19950304 the issue have been fixed on master, pls try and test.