{
  "id": "java/mockito-injectmocks-failure",
  "signature": "org.mockito.exceptions.base.MockitoException: Cannot instantiate @InjectMocks field named 'service' of type 'class com.example.MyService'",
  "signature_zh": "无法实例化 @InjectMocks 字段 'service'，类型为 'class com.example.MyService'",
  "regex": "org\\.mockito\\.exceptions\\.base\\.MockitoException:\\ Cannot\\ instantiate\\ @InjectMocks\\ field\\ named\\ 'service'\\ of\\ type\\ 'class\\ com\\.example\\.MyService'",
  "domain": "java",
  "category": "config_error",
  "subcategory": null,
  "root_cause": "@InjectMocks requires a no-arg constructor or constructor injection, but class lacks one or has ambiguous constructors.",
  "root_cause_type": "generic",
  "root_cause_zh": "@InjectMocks 需要无参构造函数或构造函数注入，但类缺少无参构造函数或有歧义的构造函数。",
  "versions": [
    {
      "version": "8+",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Adding @InjectMocks to a field with private constructor",
      "why_fails": "Mockito cannot instantiate the class.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "Using @Spy on the same field",
      "why_fails": "Spy requires an instance; @InjectMocks is for creating instances.",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Provide a no-arg constructor in production class",
      "success_rate": 0.9,
      "how": "public MyService() {\n    // default constructor\n}",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use manual construction with mocks",
      "success_rate": 0.85,
      "how": "MyService service = new MyService(mockDep1, mockDep2);",
      "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.87,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-10-05",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}