# java.lang.AssertionError: expected:<X> but was:<Y>

- **ID:** `java/assertion-error`
- **Domain:** java
- **Category:** assertion_error
- **Verification:** ai_generated
- **Fix Rate:** 90%

## Root Cause

AssertionError is thrown when a Java assertion (assert statement) fails, typically used for debugging or testing to verify invariants, or when a test framework like JUnit detects a failed assertion.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Java 8 | active | — | — |
| Java 11 | active | — | — |
| Java 17 | active | — | — |
| JUnit 4.13 | active | — | — |
| JUnit 5.9 | active | — | — |

## Workarounds

1. **Fix the code logic to ensure the assertion condition is true. For example, if the assertion is 'assert x == 10', correct the variable x to equal 10 before the assertion.** (95% success)
   ```
   Fix the code logic to ensure the assertion condition is true. For example, if the assertion is 'assert x == 10', correct the variable x to equal 10 before the assertion.
   ```
2. **Use a proper testing framework like JUnit with assertEquals(expected, actual) instead of assert statements, which provides better error messages and is always enabled.** (90% success)
   ```
   Use a proper testing framework like JUnit with assertEquals(expected, actual) instead of assert statements, which provides better error messages and is always enabled.
   ```

## Dead Ends

- **** — AssertionError indicates a programming error; ignoring it allows the bug to persist and may cause unpredictable behavior later. (80% fail)
- **** — Assertions are a development-time tool; disabling them does not fix the underlying issue and can lead to silent failures. (90% fail)
