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

math/big: big.Int.MarshalJSON produces invalid json for nil #50940

Closed
Snaipe opened this issue Feb 1, 2022 · 3 comments
Closed

math/big: big.Int.MarshalJSON produces invalid json for nil #50940

Snaipe opened this issue Feb 1, 2022 · 3 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@Snaipe
Copy link

Snaipe commented Feb 1, 2022

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

$ go version
go version go1.17.6 linux/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/snaipe/.local/var/cache/go-build"
GOENV="/home/snaipe/.local/etc/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/snaipe/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/snaipe/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.17.6"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/snaipe/b5/src/snai.pe/boa/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3656356402=/tmp/go-build -gno-record-gcc-switches"

What did you do?

https://play.golang.com/p/Zz6ueutEwo7

What did you expect to see?

MarshalJSON should return the JSON null value.

What did you see instead?

MarshalJSON instead returns <nil> with no error, which is invalid JSON. At the very least, if MarshalJSON should not return null for nil *big.Int, an error should be returned rather than producing invalid JSON.

@gopherbot
Copy link
Contributor

Change https://golang.org/cl/381963 mentions this issue: math: fix big.Int MarshalJSON when x is nil

@nightlyone
Copy link
Contributor

Should the big.Int.Unmarshal also parse this somehow to keep it symmetrical?

@Snaipe
Copy link
Author

Snaipe commented Feb 1, 2022

big.Int.UnmarshalJSON already parses null so this would make things more consistent, as you pointed out.

@toothrot toothrot added this to the Backlog milestone Feb 4, 2022
@toothrot toothrot added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Feb 4, 2022
cuiweixie added a commit to cuiweixie/go that referenced this issue Feb 12, 2022
@dmitshur dmitshur added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. labels Mar 4, 2022
@dmitshur dmitshur modified the milestones: Backlog, Go1.19 Mar 4, 2022
@golang golang locked and limited conversation to collaborators Mar 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants