encoding/gob: decoding fails for structs with anonymous pointer fields that implement GobDecoder interface #31781
Labels
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I am using the gob encoder/decoder to serialize and deserialize the strut into a byte array. I ran into an issue when
big.Rat
embedded into another struct. I am able to successfully encode and decodebig.Rat
type directly without any issue. Butbig.Rat
is embedded into another strut then I am able to encode successfully but during the decoding process, it throws panic: runtime error: invalid memory address or nil pointer dereference.BTW, to solve this issue, I added implemented the GobEncoder/GobDecoder for the custom strut.
Link to go playground https://play.golang.org/p/98PzJDqm0QL
The below code produces the issue and we can uncomment GobEncoder/GobDecoder to successfully run the example.
Code sample:
What did you expect to see?
I expect to see successful encoding/decoding when
big.Rat
whether it is embedded into another strut or not.What did you see instead?
The
big.Rat
decoding fails when it is embedded into another strut. Please see the example code above.The text was updated successfully, but these errors were encountered: