Fix code quality issues in DocumentDirtyTracker: mutable static, redundant I/O, test coverage#79
Merged
carstenartur merged 2 commits intoFeb 7, 2026
Conversation
…te getDocument calls, add incremental edit tests Co-authored-by: carstenartur <3164220+carstenartur@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix code quality issues in DocumentDirtyTracker
Fix code quality issues in DocumentDirtyTracker: mutable static, redundant I/O, test coverage
Feb 7, 2026
carstenartur
approved these changes
Feb 7, 2026
689dbf6
into
copilot/fix-string-index-out-of-bounds
3 checks passed
jjohnstn
pushed a commit
that referenced
this pull request
Feb 10, 2026
…ndant I/O, test coverage (#79)
github-actions Bot
pushed a commit
that referenced
this pull request
Mar 25, 2026
Tests in SaveParticipantTest sporadically fail with org.eclipse.text.edits.MalformedTreeException, potentially due to concurrent text store modifications. This change enables debug tracing of org.eclipse.text during the test, so that text store modifications are traced. See: #79
github-actions Bot
pushed a commit
that referenced
this pull request
Mar 30, 2026
This change cancels and joins the family DecoratorManager.FAMILY_DECORATE after a Java editor is opened in SaveParticipantTest. The job is occasionally seen in debug traces, adding element infos to JavaModelManager.cache. Additionally it can open and close buffers at org.eclipse.jdt.internal.core.BufferManager, where buffers from the BufferManager are used for retrieving the contents of files that should be formatted on save. The change also adds debug traces for BufferManager. See: #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.
Three code quality issues in the DocumentDirtyTracker feature: a mutable object shared as static final, redundant document buffer connections, and tests only exercising bulk replacement instead of incremental edits.
Changes
Removed shared mutable static field
CleanUpPostSaveListenerhadprivate static final NullProgressMonitor NULL_PROGRESS_MONITOR. SinceNullProgressMonitor.setCanceled(true)mutates state, sharing one instance across all calls creates potential for leaked state. Replaced withnew NullProgressMonitor()at each use site.Consolidated duplicate getDocument() calls
The
saved()method calledgetDocument(unit)twice:Each call does a connect/disconnect cycle. Now cache document and tracker references to eliminate the second I/O round-trip.
Added incremental edit tests
Existing tests only used
document.set()which replaces entire document content. Added four tests usingdocument.replace(offset, length, text)to exercise:These test the actual DocumentDirtyTracker behavior during real editing scenarios where changes are incremental.
Original prompt
Code Quality Fixes for PR eclipse-jdt#2778
This PR fixes three code quality issues in the
copilot/fix-string-index-out-of-boundsbranch that were introduced by the DocumentDirtyTracker feature.1. Mutable
NullProgressMonitorasstatic finalfieldFile:
org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/fix/CleanUpPostSaveListener.javaProblem (line 309):
NullProgressMonitoris mutable — methods likesetCanceled(true)can change its state. If shared as astatic finalfield, a call tosetCanceled()could affect all subsequent uses. The rest of the class already correctly createsnew NullProgressMonitor()each time.Fix: Remove the
static finalfield and usenew NullProgressMonitor()in each call site (lines 698 and 703 ingetDocument()).2.
getDocument()connect/disconnect lifecycle issueFile:
org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/fix/CleanUpPostSaveListener.javaProblem (lines 692-705):
The document is returned but the buffer is immediately disconnected in the
finallyblock. The document object stays in memory but is conceptually no longer connected to the buffer. Additionally,getDocument()is called twice in thesaved()method (once at line 340 and once at line 444), each time doing a connect/disconnect cycle.Fix: Refactor so that the method is more robust. The simplest approach: since this code runs during a save operation where the document is already open in an editor, the buffer is already connected by the editor infrastructure. We should still connect/disconnect properly but the pattern should be clearer. At minimum, consolidate the two
getDocument()calls to avoid redundant connect/disconnect cycles.3. Tests use
document.set()instead of incremental editsFile:
org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/DocumentDirtyTrackerTest.javaProblem: The tests use
document.set("...")which replaces the entire document content. This fires only a singledocumentChangedevent with offset=0 and length=entire document. In reality, edits are done viadocument.replace(offset, length, text)which exercises the tracking very differently. The tests could pass even if the tracker doesn't work correctly for real incremental edits.Fix: Add additional test methods (or modify existing ones) that use
document.replace(offset, length, text)for incremental edits. Keep some of thedocument.set()tests as they test the bulk-replacement case, but add tests like: