# java.lang.ClassNotFoundException: com.example.MyHandler : Error loading class from SnapStart snapshot

- **ID:** `aws/lambda-snapstart-java-class-not-found`
- **Domain:** aws
- **Category:** runtime_error
- **Error Code:** `ClassNotFoundException`
- **Verification:** ai_generated
- **Fix Rate:** 78%

## 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.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| AWS Lambda Java 11 runtime | active | — | — |
| AWS Lambda Java 17 runtime | active | — | — |
| SnapStart (2023-04-01) | active | — | — |

## Workarounds

1. **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').** (88% success)
   ```
   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').
   ```
2. **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.** (75% success)
   ```
   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.
   ```
3. **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.** (82% success)
   ```
   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.
   ```

## Dead Ends

- **** — Rebuilding the deployment package without cleaning the build cache may include stale class files that don't match the SnapStart snapshot. (55% fail)
- **** — Adding the class to the system classpath via environment variables (e.g., CLASSPATH) is ignored by SnapStart because it uses a pre-initialized JVM. (70% fail)
- **** — 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. (45% fail)
