{
  "id": "java/mockito-when-thenreturn-null-pointer",
  "signature": "java.lang.NullPointerException: Cannot invoke \"Object.getClass()\" because \"answer\" is null",
  "signature_zh": "空指针异常：无法调用“Object.getClass()”，因为“answer”为空",
  "regex": "java\\.lang\\.NullPointerException:\\ Cannot\\ invoke\\ \"Object\\.getClass\\(\\)\"\\ because\\ \"answer\"\\ is\\ null",
  "domain": "java",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Mockito.when() called with a method that returns null, or the mock object is not initialized.",
  "root_cause_type": "generic",
  "root_cause_zh": "Mockito.when() 调用的方法返回 null，或者模拟对象未初始化。",
  "versions": [
    {
      "version": "8+",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Adding @Mock annotation without MockitoAnnotations.openMocks()",
      "why_fails": "Annotations not processed, mock remains null.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "Using when().thenReturn() on a final method without mockito-inline",
      "why_fails": "Mockito cannot mock final methods by default, causing NPE.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Initialize mocks explicitly in @BeforeEach",
      "success_rate": 0.95,
      "how": "@BeforeEach\nvoid setUp() {\n    MockitoAnnotations.openMocks(this);\n}",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use mock() method directly",
      "success_rate": 0.9,
      "how": "MyService service = mock(MyService.class);\nwhen(service.getData()).thenReturn(\"test\");",
      "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.85,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-03-15",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}