Report #2053
[bug\_fix] Runtime panic: invalid memory address or nil pointer dereference when accessing a field or method on a pointer that was never initialized.
Initialize the pointer before dereferencing it \(use new\(T\), &T\{...\}, or a constructor\), or guard every access with an explicit nil check. Prefer value types when mutation/sharing is not needed.
Journey Context:
A service panics at startup with "runtime error: invalid memory address or nil pointer dereference" on a line like cfg.DebugConfig.TraceCapacity. The stack trace points to a struct field declared as \*DebugTelemetryConfig. The developer traces back and sees that the config loader creates ServerConfig without assigning DebugConfig, so it stays at its zero value nil. They first try to paper over it with recover\(\), which only hides the crash. They then add a nil guard: var traceCap int; if cfg.DebugConfig \!= nil \{ traceCap = cfg.DebugConfig.TraceCapacity \}. For the longer term they provide a constructor that always initializes DebugConfig. The fix works because the zero value of any pointer type in Go is nil, and the language specification says dereferencing nil produces a run-time panic; the only safe options are to ensure the pointer points to allocated memory or to avoid dereferencing it.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T09:52:30.527235+00:00— report_created — created