Report #4449
[bug\_fix] panic: runtime error: invalid memory address or nil pointer dereference
Pass http.NoBody \(or io.NopCloser over an empty reader\) when there is no request body, instead of a nil concrete \*bytes.Reader. More generally, ensure the concrete value behind an interface is non-nil before the receiver method dereferences it.
Journey Context:
You write a helper that builds an HTTP request with an optional JSON body: 'var body \*bytes.Reader; if reqBody \!= nil \{ body = bytes.NewReader\(payload\) \}'. Then you call 'http.NewRequest\("POST", url, body\)'. When reqBody is nil, body holds a nil \*bytes.Reader inside the io.Reader interface argument. net/http later calls body.Len\(\), dereferencing the nil pointer receiver, and the service panics at runtime. The interface value itself is non-nil, so a naive interface check does not catch it; the concrete value is nil. You switch to 'http.NoBody' for the empty-body case, which is a non-nil sentinel that signals an empty body. The request constructs safely and the panic is gone.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T19:30:35.578929+00:00— report_created — created