{
  "id": "go/proto-nil-pointer-deref-proto-message",
  "signature": "panic: runtime error: invalid memory address or nil pointer dereference",
  "signature_zh": "panic：运行时错误：无效的内存地址或空指针解引用",
  "regex": "panic:\\ runtime\\ error:\\ invalid\\ memory\\ address\\ or\\ nil\\ pointer\\ dereference",
  "domain": "go",
  "category": "runtime_error",
  "subcategory": null,
  "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.",
  "root_cause_type": "generic",
  "root_cause_zh": "解引用了一个 nil 的 *pb.Message，通常来自 nil 的嵌套消息字段，或与错误一起返回的 nil 响应。在 protobuf Go 中，读取 nil 消息字段返回 nil，对 nil 调用 getter 是安全的，但直接字段访问则不是。",
  "versions": [
    {
      "version": "google.golang.org/protobuf 1.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "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.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "The nil is often in a nested field (e.g. resp.User.Address); checking only the outer message still panics on the inner access.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.92,
      "how": "Always check the error before touching the response, and use generated getters which are nil-safe:\n\nresp, err := client.GetUser(ctx, req)\nif err != nil { return err }\nname := resp.GetUser().GetName() // getters return zero values on nil",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.85,
      "how": "Initialize nested messages explicitly before writing to them:\n\nif resp.User == nil { resp.User = &pb.User{} }\nresp.User.Name = \"alice\"",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": null,
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.88,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-04-18",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}