fix: resolve crashes in DiffStreamHandler — unsafe cast and negative line numbers#11893
Conversation
…line numbers - Use safe cast (as?) for TextEditor in undoChanges() to prevent ClassCastException - Add early return for empty documents and clamp line numbers to prevent IndexOutOfBoundsException in initUnfinishedRangeHighlights() - Remove redundant .toList() call in rejectAll() Fixes #4267
Docs ReviewNo documentation updates needed for this PR. Reasoning: These changes are internal defensive programming fixes to the JetBrains IntelliJ extension's |
Test Coverage ReviewThis PR fixes crash conditions in
Missing Regression TestsPer the test coverage guidelines, bug fixes should include regression tests that reproduce the original bug condition and verify the fix. Consider adding tests for:
The IntelliJ test infrastructure ( Automated test coverage check |
Summary
as?) forTextEditorinundoChanges()to preventClassCastException/NullPointerExceptionwhen the selected editor is not aTextEditorcoerceAtLeast(0)ininitUnfinishedRangeHighlights()to preventIndexOutOfBoundsException.toList()call inrejectAll()— the list was already copied on the previous lineFixes #4267
Test plan
initUnfinishedRangeHighlights()undoChanges()when the active editor is not aTextEditor(e.g., image viewer) — verify graceful no-op instead of crashSummary by cubic
Fixes two crashes in
DiffStreamHandlerby safely handling non-TextEditorcases and clamping line numbers for empty or short documents. Prevents crashes when opening diffs on empty files and when undo is triggered in non-text editors. Fixes #4267.Bug Fixes
undoChanges()and no-op if not aTextEditorto avoidClassCastException/NullPointerException.initUnfinishedRangeHighlights()to avoidIndexOutOfBoundsException.Refactors
.toList()inrejectAll()to avoid an extra allocation.lineNumininitUnfinishedRangeHighlights()for clarity.Written for commit 324f1a1. Summary will update on new commits.