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/binary: handle unexported fields more gracefully #19794

Closed
dominikh opened this issue Mar 30, 2017 · 2 comments
Closed

encoding/binary: handle unexported fields more gracefully #19794

dominikh opened this issue Mar 30, 2017 · 2 comments
Labels
Documentation FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@dominikh
Copy link
Member

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

go version go1.8 linux/amd64

What did you do?

https://play.golang.org/p/gcvrJJD1uS

What did you expect to see?

Either an error to be returned, or the unexported fields to be skipped.

What did you see instead?

panic: reflect: reflect.Value.SetUint using value obtained using unexported field

goroutine 1 [running]:
reflect.flag.mustBeAssignable(0x1a8, 0x0)
	/usr/local/go/src/reflect/value.go:225 +0x1c0
reflect.Value.SetUint(0xf1e00, 0x1040a0d9, 0x1a8, 0x1ce2, 0x78, 0x0)
	/usr/local/go/src/reflect/value.go:1493 +0x40
encoding/binary.(*decoder).value(0x10429f5c, 0xf1e00, 0x1040a0d9, 0x1a8)
	/usr/local/go/src/encoding/binary/binary.go:546 +0xac0
encoding/binary.(*decoder).value(0x10429f5c, 0xf4760, 0x1040a0d9, 0x199)
	/usr/local/go/src/encoding/binary/binary.go:521 +0x320
encoding/binary.Read(0x170630, 0x10440240, 0x1714c0, 0x1931c8, 0xe89a0, 0x1040a0d9, 0x0, 0x2)
	/usr/local/go/src/encoding/binary/binary.go:247 +0x1360
main.main()
	/tmp/sandbox482800808/main.go:16 +0x120
@SamWhited
Copy link
Member

SamWhited commented May 10, 2017

The documentation for Read says:

When reading into a struct, all non-blank fields must be exported.

That seems to me to indicate that the panic is expected (although that could be made more clear: "~ or Read may panic"). It occurs as far back as Go 1.5, so it does not appear to be a regression.

I've marked this as a Documentation issue for now; if you intended it to be a proposal we can change it.

@SamWhited SamWhited added this to the Go1.9Maybe milestone May 10, 2017
@bradfitz bradfitz added the NeedsFix The path to resolution is known, but the work has not been done. label Jun 28, 2017
@gopherbot
Copy link

CL https://golang.org/cl/47093 mentions this issue.

@golang golang locked and limited conversation to collaborators Jun 29, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Documentation FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants