Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
encoding/json: non-string map keys cause panic #8305
What does 'go version' print? go version go1.3 linux/amd64 What steps reproduce the problem? http://play.golang.org/p/lVP3r71dWS 1. Use a non-string key in a map to unmarshal into What happened? Invalid conversion inside the encoding/json decoder. Resulting in a panic. What should have happened instead? No panic should've happened. Please provide any additional information below. There are two bugs in play here. The first panic occurs because the check for a map[string]T does not exit the decoding step when it doesn't hold. This is visible at http://golang.org/src/pkg/encoding/json/decode.go#L481 and the break on this line should be a return. The second panic, the one shown to the user occurs because the encoding/json package uses panics as a unwinding mechanism, and always expects the argument given to panic to be an error. In the case of an unexpected panic which does not send an error type, the type assertion on http://golang.org/src/pkg/encoding/json/decode.go#L137 fails and is propagated to the package user. I'm of the opinion that the type-assertion panic should not be fixed, since it will hide implementation bugs such as these.