Fix race condition in "Format edited lines" causing StringIndexOutOfBoundsException#2778
Open
carstenartur wants to merge 14 commits intoeclipse-jdt:masterfrom
Open
Fix race condition in "Format edited lines" causing StringIndexOutOfBoundsException#2778carstenartur wants to merge 14 commits intoeclipse-jdt:masterfrom
carstenartur wants to merge 14 commits intoeclipse-jdt:masterfrom
Conversation
…ener - Created DocumentDirtyTracker to track dirty lines internally and prevent race conditions - Modified CleanUpPostSaveListener to use DocumentDirtyTracker for region calculation - Added defensive bounds checking in validateRegions method - Initialized tracker in CompilationUnitDocumentProvider.connect() Co-authored-by: carstenartur <3164220+carstenartur@users.noreply.github.com>
- Created DocumentDirtyTrackerTest with 14 test cases - Tests cover single/multiple edits, line insertion/deletion, UTF-8 handling - Tests verify region bounds validation and concurrent document tracking - Added test to JdtTextTestSuite Co-authored-by: carstenartur <3164220+carstenartur@users.noreply.github.com>
- Fixed linesRemoved calculation by using documentAboutToBeChanged to capture state before modification - Changed dirty line marking to only mark start and end lines, not all intermediate lines - Improved bounds validation to properly handle empty regions at document end - Changed test assertions from assertEquals to assertTrue for better readability Co-authored-by: carstenartur <3164220+carstenartur@users.noreply.github.com>
- Use Collections.synchronizedMap for thread-safe WeakHashMap - Remove double-locking by simplifying get() and dispose() methods - Use static NullProgressMonitor instance to reduce allocations - Extract isValidRegion() helper method with clear documentation Co-authored-by: carstenartur <3164220+carstenartur@users.noreply.github.com>
- Document thread-safety assumption for lineCountBeforeChange (IDocument guarantees serialized changes) - Fix logic to clear dirty lines after finally block, using saved needsChangedRegions flag - Add clarifying comment about DocumentDirtyTracker.get() side effect in CompilationUnitDocumentProvider Co-authored-by: carstenartur <3164220+carstenartur@users.noreply.github.com>
- Changed imports from org.junit.* to org.junit.jupiter.api.* - Removed unused assertArrayEquals import - Changed @before to @beforeeach and @after to @AfterEach - Fixed build compilation error Co-authored-by: carstenartur <3164220+carstenartur@users.noreply.github.com>
- Changed all assertions to use correct JUnit 5 parameter order (value first, message last) - Fixed assertNull, assertNotNull, assertEquals, and assertTrue calls - Resolved build compilation errors Co-authored-by: carstenartur <3164220+carstenartur@users.noreply.github.com>
2091c33 to
287b81d
Compare
…ndant I/O, test coverage (#79)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix race condition in "Format edited lines" causing StringIndexOutOfBoundsException
External region calculation becomes stale between computation and formatter invocation, causing crashes in
TokenManager.countLineBreaksBetween()when offsets are invalid.Solution
Introduces
DocumentDirtyTrackerthat maintains dirty line state within the document lifecycle:DocumentDirtyTracker (new)
IDocumentListener, adjusts on insert/deletedocumentAboutToBeChanged()to capture pre-modification stateCollections.synchronizedMap(WeakHashMap)CleanUpPostSaveListener
validateRegions()with defensive bounds checkingCompilationUnitDocumentProvider
Edge Cases Handled
Tests
Original prompt
This pull request was created from Copilot chat.
What it does
How to test
Author checklist