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

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

## Root Cause

A nil *Message pointer was passed to proto.Marshal, proto.Clone, or a generated getter was called on a nil receiver that dereferences a map field.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| google.golang.org/protobuf v1.28+ | active | — | — |

## Workarounds

1. **** (95% success)
   ```
   if msg == nil {
    return nil, status.Error(codes.InvalidArgument, "nil message")
}
data, err := proto.Marshal(msg)
if err != nil { return nil, err }
   ```
2. **** (85% success)
   ```
   clone := proto.Clone(msg) // returns nil if msg is nil
if clone == nil {
    return nil, errors.New("nil proto message")
}
   ```

## Dead Ends

- **** — Masks the nil bug; the same nil pointer will surface elsewhere or cause silent data loss. (85% fail)
- **** — AllowPartial only affects required-field validation, not nil pointer dereferences. (95% fail)
