-
Notifications
You must be signed in to change notification settings - Fork 18k
encoding/json: panic on recover #3614
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
Labels
Milestone
Comments
My guess is that you passed a struct (not a struct pointer) to encoding/json and that the string was one of the fields in the struct. It would be good to test this theory and if so make Unmarshal give a better error. I will do this if no one else beats me to it, but probably not soon. Labels changed: added go1.0.2. |
You're right. I have attached the reproducer. It currently fails with the same stack trace: panic: reflect.Value.SetString using unaddressable value [recovered] panic: interface conversion: string is not error: missing method Error goroutine 1 [running]: encoding/json._func_001(0x7fa2a20e0e88, 0x7fa2a1fc0100, 0x7fa2a1fc0fb8, 0x7fa2a1fc0b98) /usr/local/go/src/pkg/encoding/json/decode.go:123 +0xaf ----- stack segment boundary ----- reflect.flag.mustBeAssignable(0x182, 0x1800000000) /usr/local/go/src/pkg/reflect/value.go:268 +0x166 reflect.Value.SetString(0x4626a0, 0xf84002e230, 0x182, 0xf84003c130, 0x200000002, ...) /usr/local/go/src/pkg/reflect/value.go:1336 +0x25 encoding/json.(*decodeState).literalStore(0xf840059000, 0xf84002e24a, 0x600000004, 0x4626a0, 0xf84002e230, ...) /usr/local/go/src/pkg/encoding/json/decode.go:651 +0x730 ----- stack segment boundary ----- encoding/json.(*decodeState).literal(0xf840059000, 0x4626a0, 0xf84002e230, 0x182) /usr/local/go/src/pkg/encoding/json/decode.go:581 +0xb7 encoding/json.(*decodeState).value(0xf840059000, 0x4626a0, 0xf84002e230, 0x182) /usr/local/go/src/pkg/encoding/json/decode.go:252 +0x1b1 encoding/json.(*decodeState).object(0xf840059000, 0x473fd8, 0xf84002e230, 0x192) /usr/local/go/src/pkg/encoding/json/decode.go:550 +0xa1c encoding/json.(*decodeState).value(0xf840059000, 0x461198, 0xf84002e220, 0x146) /usr/local/go/src/pkg/encoding/json/decode.go:249 +0x1da encoding/json.(*decodeState).object(0xf840059000, 0x473f60, 0xf84002e220, 0x196) /usr/local/go/src/pkg/encoding/json/decode.go:550 +0xa1c encoding/json.(*decodeState).value(0xf840059000, 0x4600b8, 0xf84002e220, 0x160) /usr/local/go/src/pkg/encoding/json/decode.go:249 +0x1da encoding/json.(*decodeState).unmarshal(0xf840059000, 0x4600a8, 0xf84002e220, 0x0, 0x0, ...) /usr/local/go/src/pkg/encoding/json/decode.go:136 +0x159 encoding/json.Unmarshal(0xf84002e240, 0x1000000010, 0x4600a8, 0xf84002e220, 0xf84002e230, ...) /usr/local/go/src/pkg/encoding/json/decode.go:65 +0xef main.main() /home/krasin/json.go:11 +0x11c goroutine 2 [syscall]: created by runtime.main /usr/local/go/src/pkg/runtime/proc.c:221 exit status 2 Attachments:
|
Owner changed to builder@golang.org. Status changed to Accepted. |
Here's a smaller test case: func TestInterfaceSet(t *testing.T) { b := struct{ X interface{} }{"foo"} const blob = `{"X":"bar"}` if err := Unmarshal([]byte(blob), &b); err != nil { t.Errorf("%v", err) } } It's trying to update a string value that isn't addressable because it's stored as an interface value. The containing struct is addressable, so the json package could be clever enough to walk back up and the value correctly. Not sure that it's worth it, though. |
This issue was closed by revision 09b736a. Status changed to Fixed. |
rsc
added a commit
that referenced
this issue
May 11, 2015
…il interface value ««« backport bee83c1509a3 encoding/json: fix panic unmarshaling into non-nil interface value Fixes #3614. R=golang-dev, adg CC=golang-dev https://golang.org/cl/6306051 »»»
This issue was closed.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
The text was updated successfully, but these errors were encountered: