# java.lang.StringIndexOutOfBoundsException: String index out of range: 10

- **ID:** `java/string-index-out-of-bounds-exception`
- **Domain:** java
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 88%

## Root Cause

An attempt to access a character in a String using an index that is negative or greater than or equal to the string length, often due to off-by-one errors or malformed input.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Java 8 | active | — | — |
| Java 11 | active | — | — |
| Java 17 | active | — | — |
| Java 21 | active | — | — |

## Workarounds

1. **Check the string length before accessing: if (index >= 0 && index < str.length()) { char c = str.charAt(index); } else { /* handle error */ }** (95% success)
   ```
   Check the string length before accessing: if (index >= 0 && index < str.length()) { char c = str.charAt(index); } else { /* handle error */ }
   ```
2. **Use str.substring(start, end) with bounds checking, or use str.charAt(Math.min(index, str.length()-1)) as a temporary clamp.** (80% success)
   ```
   Use str.substring(start, end) with bounds checking, or use str.charAt(Math.min(index, str.length()-1)) as a temporary clamp.
   ```

## Dead Ends

- **** — This hides the bug and may cause downstream issues like null pointer exceptions or incorrect data processing. (70% fail)
- **** — This does not address the root cause of incorrect index calculation; the index may still be out of range for other inputs. (85% fail)
