{
  "id": "aws/lambda-snapstart-java-class-not-found",
  "signature": "java.lang.ClassNotFoundException: com.example.MyHandler : Error loading class from SnapStart snapshot",
  "signature_zh": "java.lang.ClassNotFoundException: com.example.MyHandler : 从 SnapStart 快照加载类时出错",
  "regex": "java\\.lang\\.ClassNotFoundException: [\\w.]+ : Error loading class from SnapStart snapshot",
  "domain": "aws",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "The Lambda function's handler class is not in the Java classpath or the SnapStart snapshot was built with a different classpath configuration, causing a mismatch during restoration.",
  "root_cause_type": "generic",
  "root_cause_zh": "Lambda 函数的处理程序类不在 Java 类路径中，或者 SnapStart 快照是在不同的类路径配置下构建的，导致恢复期间不匹配。",
  "versions": [
    {
      "version": "AWS Lambda Java 11 runtime",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "AWS Lambda Java 17 runtime",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "SnapStart (2023-04-01)",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Rebuilding the deployment package without cleaning the build cache may include stale class files that don't match the SnapStart snapshot.",
      "fail_rate": 0.55,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Adding the class to the system classpath via environment variables (e.g., CLASSPATH) is ignored by SnapStart because it uses a pre-initialized JVM.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Assuming it's a runtime dependency issue and adding all JARs to the deployment package, when the real issue is a handler class name typo.",
      "fail_rate": 0.45,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Verify the handler class is in the deployment package: `jar tf my-function.jar | grep MyHandler`. If missing, rebuild with correct classpath. Then update the Lambda handler to the fully qualified class name (e.g., 'com.example.MyHandler::handleRequest').",
      "success_rate": 0.88,
      "how": "Verify the handler class is in the deployment package: `jar tf my-function.jar | grep MyHandler`. If missing, rebuild with correct classpath. Then update the Lambda handler to the fully qualified class name (e.g., 'com.example.MyHandler::handleRequest').",
      "condition": "",
      "sources": []
    },
    {
      "action": "Disable SnapStart and redeploy: `aws lambda update-function-configuration --function-name my-function --snap-start ApplyOn=None`. After confirming the function works, re-enable SnapStart with a fresh snapshot.",
      "success_rate": 0.75,
      "how": "Disable SnapStart and redeploy: `aws lambda update-function-configuration --function-name my-function --snap-start ApplyOn=None`. After confirming the function works, re-enable SnapStart with a fresh snapshot.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use a build tool like Maven Shade Plugin or Gradle Shadow to create a fat JAR that includes all dependencies and the correct handler class, then deploy with SnapStart enabled.",
      "success_rate": 0.82,
      "how": "Use a build tool like Maven Shade Plugin or Gradle Shadow to create a fat JAR that includes all dependencies and the correct handler class, then deploy with SnapStart enabled.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "验证处理程序类是否在部署包中：`jar tf my-function.jar | grep MyHandler`。如果缺失，使用正确的类路径重新构建。然后将 Lambda 处理程序更新为完全限定的类名（例如 'com.example.MyHandler::handleRequest'）。",
    "禁用 SnapStart 并重新部署：`aws lambda update-function-configuration --function-name my-function --snap-start ApplyOn=None`。确认函数正常工作后，使用新的快照重新启用 SnapStart。",
    "使用 Maven Shade Plugin 或 Gradle Shadow 等构建工具创建包含所有依赖项和正确处理程序类的 fat JAR，然后启用 SnapStart 进行部署。"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://docs.aws.amazon.com/lambda/latest/dg/snapstart.html",
  "official_doc_section": null,
  "error_code": "ClassNotFoundException",
  "verification_tier": "ai_generated",
  "confidence": 0.82,
  "fix_success_rate": 0.78,
  "resolvable": "true",
  "first_seen": "2023-05-20",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}