# java.lang.AssertionError: expected null, but was: <some value>

- **ID:** `java/assertion-error-expected-not-null`
- **Domain:** java
- **Category:** assertion_error
- **Verification:** ai_generated
- **Fix Rate:** 78%

## Root Cause

An assertion in the code (typically from a test framework like JUnit or an explicit assert statement) failed because a value that was expected to be null was not null, indicating a logic error in null handling.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| JUnit 4.13 | active | — | — |
| JUnit 5.10 | active | — | — |
| Java 8+ | active | — | — |

## Workarounds

1. **Trace back to the source of the non-null value. For example, if a method is expected to return null but returns a value, add debug logging: System.out.println("Value: " + value); and check the method's logic.** (80% success)
   ```
   Trace back to the source of the non-null value. For example, if a method is expected to return null but returns a value, add debug logging: System.out.println("Value: " + value); and check the method's logic.
   ```
2. **Use a conditional breakpoint in the IDE (e.g., IntelliJ IDEA) set on the assertion line to inspect variables when the assertion fails.** (85% success)
   ```
   Use a conditional breakpoint in the IDE (e.g., IntelliJ IDEA) set on the assertion line to inspect variables when the assertion fails.
   ```
3. **If using JUnit, replace assertNull with assertNotNull if the expectation is incorrect, or use assertNull(obj, "message") to add a descriptive message for debugging.** (75% success)
   ```
   If using JUnit, replace assertNull with assertNotNull if the expectation is incorrect, or use assertNull(obj, "message") to add a descriptive message for debugging.
   ```

## Dead Ends

- **Remove the assertion entirely from the code** — This suppresses the symptom but does not fix the underlying null-handling bug; the logic may still produce incorrect results. (95% fail)
- **Change the expected value in the assertion to match the actual value** — This bypasses the validation and may hide a real bug where null was expected but a non-null value indicates an error in the system. (90% fail)
- **Add a try-catch block to swallow the AssertionError** — AssertionErrors are not meant to be caught; swallowing them violates the intent of the assertion and can lead to silent failures. (85% fail)
