{
  "id": "go/grpc-protobuf-oneof-nil-pointer",
  "signature": "panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV]",
  "signature_zh": "恐慌：运行时错误：无效的内存地址或空指针解引用 [信号SIGSEGV]",
  "regex": "panic:\\ runtime\\ error:\\ invalid\\ memory\\ address\\ or\\ nil\\ pointer\\ dereference\\ \\[signal\\ SIGSEGV\\]",
  "domain": "go",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Accessing a protobuf oneof field without checking if it is set, leading to nil pointer dereference.",
  "root_cause_type": "generic",
  "root_cause_zh": "访问protobuf oneof字段而未检查是否已设置，导致空指针解引用。",
  "versions": [
    {
      "version": "1.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "1.1",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Use a type switch without nil check.",
      "why_fails": "Oneof interface can be nil; type switch panics.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    },
    {
      "action": "Assume the oneof is always populated.",
      "why_fails": "Unmarshal may leave it nil if field is absent.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Check if oneof field is non-nil before type assertion.",
      "success_rate": 0.98,
      "how": "if v := msg.GetPayload(); v != nil {\n    switch x := v.(type) {\n    case *pb.Payload_Text:\n        fmt.Println(x.Text)\n    }\n}",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use proto.GetField to safely retrieve oneof values.",
      "success_rate": 0.85,
      "how": "import \"google.golang.org/protobuf/proto\"\nfield := proto.GetField(msg, \"payload\")",
      "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.86,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-07-12",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}