# panic: runtime error: invalid memory address or nil pointer dereference

- **ID:** `go/proto-nil-pointer-deref-proto-message`
- **Domain:** go
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

A nil *pb.Message was dereferenced, typically from a nil nested message field or a nil response returned alongside an error. In protobuf Go, reading a nil message field returns nil, and calling a getter on nil is safe but direct field access is not.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| google.golang.org/protobuf 1.x | active | — | — |

## Workarounds

1. **** (92% success)
   ```
   Always check the error before touching the response, and use generated getters which are nil-safe:

resp, err := client.GetUser(ctx, req)
if err != nil { return err }
name := resp.GetUser().GetName() // getters return zero values on nil
   ```
2. **** (85% success)
   ```
   Initialize nested messages explicitly before writing to them:

if resp.User == nil { resp.User = &pb.User{} }
resp.User.Name = "alice"
   ```

## Dead Ends

- **** — Recovering hides the bug and leaves the program in an inconsistent state; the nil is a logic error that must be fixed at the source. (80% fail)
- **** — The nil is often in a nested field (e.g. resp.User.Address); checking only the outer message still panics on the inner access. (70% fail)
