Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

northfun opened this issue Oct 11, 2018 · 2 comments

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

northfun opened this issue Oct 11, 2018 · 2 comments


Copy link

@northfun northfun commented Oct 11, 2018

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?

What did you expect to see?


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
	/tmp/sandbox652463797/main.go:27 +0xc0
Copy link

@mvdan mvdan commented Oct 11, 2018

Thanks for reporting! Looks like a simple bug in the reflection code. Will send a CL shortly.

@mvdan mvdan added the NeedsFix label Oct 11, 2018
@mvdan mvdan self-assigned this Oct 11, 2018
@mvdan mvdan added this to the Go1.12 milestone Oct 11, 2018
@mvdan mvdan changed the title encoding/json: json.Unmarshal on embedded unexported structs panics encoding/json: Unmarshal on unexported anonymous struct field panics Oct 11, 2018
Copy link

@gopherbot gopherbot commented Oct 11, 2018

Change mentions this issue: encoding/json: always verify we can get a field's value

@gopherbot gopherbot closed this in 4b36e12 Oct 16, 2018
@golang golang locked and limited conversation to collaborators Oct 16, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.