Navigation Menu

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: json.Unmarshal: invalid memory address or nil pointer dereference #60549

Closed
dreamans opened this issue Jun 1, 2023 · 1 comment

Comments

@dreamans
Copy link

dreamans commented Jun 1, 2023

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

$ go version

go version go1.16.8 linux/amd64

Does this issue reproduce with the latest release?

problem cannot be reproduced

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

go env Output
$ go env

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/jenkins/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/jenkins/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.16.8"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/***/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-build1677227297=/tmp/go-build -gno-record-gcc-switches"

What did you do?

type BaseResponse struct {
    Code int         `json:"code"`
    Msg  string      `json:"message"`
    Data interface{} `json:"data"`
}

var resp = new(BaseResponse)

var respBytes = []byte(`{"code":0,"msg":"success","data":null}`)

if err = json.Unmarshal(respBytes, resp); err != nil {
    log.Fatalln(err.Error())
}

What did you expect to see?

no panic

What did you see instead?

There is a panic, but it cannot be reproduced

runtime error: invalid memory address or nil pointer dereference, debugstack: /project/***/vendor/github.com/grpc-ecosystem/go-grpc-middleware/recovery/interceptors.go:29 (0xeaa570)
/usr/local/go/src/runtime/panic.go:965 (0x437478)
	gopanic: d._panic = (*_panic)(noescape(unsafe.Pointer(&p)))
/usr/local/go/src/runtime/panic.go:212 (0x43587a)
	panicmem: panic(memoryError)
/usr/local/go/src/runtime/signal_unix.go:734 (0x44e5b2)
	sigpanic: // have been delivered. Give other threads a chance to run and
/usr/local/go/src/runtime/map_faststr.go:112 (0x413b8f)
	mapaccess2_faststr: if h == nil || h.count == 0 {
/usr/local/go/src/encoding/json/decode.go:696 (0x521ccb)
	(*decodeState).object: if i, ok := fields.nameIndex[string(key)]; ok {
/usr/local/go/src/encoding/json/decode.go:370 (0x51f1cc)
	(*decodeState).value: if err := d.object(v); err != nil {
/usr/local/go/src/encoding/json/decode.go:180 (0x51e933)
	(*decodeState).unmarshal: err := d.value(rv)
/usr/local/go/src/encoding/json/decode.go:107 (0x51e2d9)
	Unmarshal: return d.unmarshal(v)
...
/usr/local/go/src/runtime/asm_amd64.s:1371 (0x46e300)
	goexit: // returns to goexit+PCQuantum.
@dreamans dreamans changed the title affected/package: encoding/json, json.Unmarshal: invalid memory address or nil pointer dereference encoding/json: json.Unmarshal: invalid memory address or nil pointer dereference Jun 1, 2023
@seankhliao
Copy link
Member

sorry, 1.16 is outside of our support window (2 most recent releases)

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Jun 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants