PDGGK opened a new pull request, #401:
URL: https://github.com/apache/dubbo-go-hessian2/pull/401

   **What this PR does**:
   
   When a Java provider returns an object with a `Map` field that holds a 
`LinkedHashMap` (or any other typed map), and that map contains further typed 
maps, decoding the response into a registered Go struct fails. On current 
master the error is `the type ref index 0 is out of range` (or index 1, 
depending on what came before), and the whole response is lost.
   
   The Java encoder writes each type name once and refers to it by index 
afterwards. `decMapByValue`, which decodes a map into a struct field, read the 
type of a typed map (`'M'`) and threw it away, so it never reached the 
decoder's type refs. From then on the Go side was one entry behind the Java 
side, and the next type ref pointed past the end of the list. `decMap` already 
reads the type with `decMapType`, which records it. `decMapByValue` now does 
the same. The type itself is still not used there.
   
   The byte dump in #351 shows exactly this shape: `parkingService` is written 
as `M 0x17 "java.util.LinkedHashMap"` and `storeService` as `M 0x91`, a ref to 
type index 1. The new test `customReplyLinkedHashMapInTreeMapField` makes 
hessian-lite produce the same bytes (a `TreeMap` field, then two nested 
`LinkedHashMap`s), and master fails on it with `the type ref index 1 is out of 
range`. The error text in the issue (`illegal class index @idx 1`) comes from 
the older release the reporter used, and their dump is truncated, so I could 
not replay their exact payload.
   
   Tests: `TestDecodeLinkedHashMapInMapField` decodes two replies produced by 
the Java test server: a `LinkedHashMap` field holding two `LinkedHashMap`s 
(nested maps are type ref 0) and a `TreeMap` field holding two `LinkedHashMap`s 
(the case from #351). With `map.go` reverted to master, both cases fail with 
the out-of-range error above. With the change both decode to the expected 
struct.
   
   `go test ./... -race`, `mvn test -f test_hessian/pom.xml`, `golangci-lint 
run` (v2.4.0), `go fmt` plus `imports-formatter`, and the license header check 
all pass locally, with JDK 8 and Go 1.25. I did not test against a running 
Dubbo provider. The replies come from the hessian-lite `Hessian2Output` in 
`test_hessian`, the same encoder Dubbo uses.
   
   **Which issue(s) this PR fixes**:
   
   Fixes #351
   
   **Special notes for your reviewer**:
   
   The only caller of `decMapByValue` is `decToDest`, used by `decInstance` for 
struct fields. A type ref that is out of range for the field map itself now 
returns an error, as it already did in `decMap`, instead of being skipped 
silently.
   
   **Does this PR introduce a user-facing change?**:
   
   ```release-note
   Fix decoding of a struct whose map field contains nested typed maps (for 
example LinkedHashMap): it failed with "the type ref index N is out of range".
   ```
   


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