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

Closed
northfun opened this issue Oct 11, 2018 · 2 comments

Comments

Projects
None yet
3 participants
@northfun
Copy link

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?

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

This comment has been minimized.

Copy link
Member

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

@gopherbot

This comment has been minimized.

Copy link

commented Oct 11, 2018

Change https://golang.org/cl/141537 mentions this issue: encoding/json: always verify we can get a field's value

@gopherbot gopherbot closed this in 4b36e12 Oct 16, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.