# org.opentest4j.AssertionFailedError: Expected java.lang.RuntimeException to be thrown, but java.lang.NullPointerException was thrown

- **ID:** `java/junit-assert-throws-wrong-type`
- **Domain:** java
- **Category:** data_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

assertThrows expects a specific exception type, but a different exception is thrown.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 8+ | active | — | — |

## Workarounds

1. **Use assertThrows with correct exception type** (95% success)
   ```
   assertThrows(NullPointerException.class, () -> {
    // code that throws NPE
});
   ```
2. **Use assertThrowsAny for multiple exception types** (80% success)
   ```
   assertThrowsAny(RuntimeException.class, () -> {
    // code
});
   ```

## Dead Ends

- **Catching the actual exception and ignoring** — Test passes incorrectly; real exception type mismatch is hidden. (60% fail)
- **Changing expected type to Exception** — Too broad; may hide other issues. (50% fail)
