#1264·zap

jsonEncoder.safeAddString panic

Author: fudali113Created Mar 27, 2023Updated Oct 10, 2025
Labelswaiting for author

https://github.com/uber-go/zap/blob/845ca51d5b8d9fed9fe14f35ab13b6b160d5762d/zapcore/json_encoder.go#L488

panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x6e42f8]

goroutine 25244385 [running]: go.uber.org/zap/zapcore.(*jsonEncoder).safeAddString(0xc0012e5bf0, {0x0, 0x4}) /build/vendor/go.uber.org/zap/zapcore/json_encoder.go:466 +0x58 go.uber.org/zap/zapcore.(*jsonEncoder).AppendString(0xc0012e5bf0, {0x0, 0x4}) /build/vendor/go.uber.org/zap/zapcore/json_encoder.go:267 +0x1f2 go.uber.org/zap/zapcore.(*jsonEncoder).AddString(0xc0005d0ca8, {0x2067ce9, 0xc0012e5bf0}, {0x0, 0x4}) /build/vendor/go.uber.org/zap/zapcore/json_encoder.go:182 +0x45 go.uber.org/zap/zapcore.Field.AddTo({{0x2067ce9, 0x7}, 0xf, 0x0, {0x0, 0x4}, {0x0, 0x0}}, {0x24f1be0, 0xc0012e5bf0}) /build/vendor/go.uber.org/zap/zapcore/field.go:149 +0x74c go.uber.org/zap/zapcore.addFields({0x24f1be0, 0xc0012e5bf0}, {0xc0012a6380, 0xe, 0x207236c}) /build/vendor/go.uber.org/zap/zapcore/field.go:210 +0xe6 go.uber.org/zap/zapcore.(*jsonEncoder).EncodeEntry(0xc000adbe30, {0x0, {0xc1005e92872d07da, 0x3e5dcd4601bd4, 0x3911600}, {0xc00029e0b0, 0xc}, {0x20a7c71, 0x19}, {0x0, ...}, ...}, ...) /build/vendor/go.uber.org/zap/zapcore/json_encoder.go:393 +0x671 gopkg.mihoyo.com/takumi/log.zapLogger.write({{0xc00029e0b0, 0xc}, {0xc0009856b0}, {0x24f2860, 0xc000adbe30}, {0x247a798, 0xc000adbe60}}, {0x0, {0xc1005e92872d07da, 0x3e5dcd4601bd4, ...}, ...}, ...)

zap version: v1.18.0

I cannot repeat this case, but this error occurs from time to time in our online environment. I hope to get help