Skip to content

encoding/json: Unmarshal on unexported anonymous struct field panics #28145

@northfun

Description

@northfun

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version go1.11 linux/amd64

Does this issue reproduce with the latest release?

yes. Does not happen with go1.9,but happen with go1.10

What operating system and processor architecture are you using (go env)?

ubuntu16.04 LTS

What did you do?

https://play.golang.org/p/Kw-Gm5YbkJw

What did you expect to see?

nil

This only happen when innerType has a method named with capital letter.If method replace to f(),the panic won't happen.

What did you see instead?

panic: reflect.Value.Interface: cannot return value obtained from unexported field or method

goroutine 1 [running]:
reflect.valueInterface(0x111880, 0x1f7264, 0x36, 0x1, 0x1, 0xe)
	/usr/local/go/src/reflect/value.go:989 +0x200
reflect.Value.Interface(0x111880, 0x1f7264, 0x36, 0x9, 0x152960, 0x111880)
	/usr/local/go/src/reflect/value.go:978 +0x40
encoding/json.indirect(0x110fe0, 0x1f7264, 0x1d9, 0x0, 0x416040, 0x5, 0x8, 0x18ec, 0x6c, 0x6c, ...)
	/usr/local/go/src/encoding/json/decode.go:486 +0x2c0
encoding/json.(*decodeState).object(0x44e060, 0x110fe0, 0x1f7264, 0x1d9, 0x44e078, 0x7b)
	/usr/local/go/src/encoding/json/decode.go:620 +0x60
encoding/json.(*decodeState).value(0x44e060, 0x110fe0, 0x1f7264, 0x1d9, 0x152960, 0x112dc0)
	/usr/local/go/src/encoding/json/decode.go:383 +0x60
encoding/json.(*decodeState).object(0x44e060, 0x111820, 0x1f7264, 0x16, 0x44e078, 0x7b)
	/usr/local/go/src/encoding/json/decode.go:781 +0x19c0
encoding/json.(*decodeState).value(0x44e060, 0x111820, 0x1f7264, 0x16, 0x44e078, 0x7d)
	/usr/local/go/src/encoding/json/decode.go:383 +0x60
encoding/json.(*decodeState).unmarshal(0x44e060, 0x111820, 0x1f7264, 0x44e078, 0x0, 0x0)
	/usr/local/go/src/encoding/json/decode.go:180 +0x240
encoding/json.Unmarshal(0x454000, 0x11a, 0x120, 0x111820, 0x1f7264, 0x11a, 0x120, 0x40e158)
	/usr/local/go/src/encoding/json/decode.go:107 +0x180
main.main()
	/tmp/sandbox652463797/main.go:27 +0xc0

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions