Skip to content

WorkspaceDiagnosticsTest matches an unchanged report again when its file's document is collected #1836

Closed

Description

@lagergren

Problem

WorkspaceDiagnosticsTest fails now and then in the tests that go through assertUnchangedMatchInvalidation. On #1835's Ubuntu job, testUnrelatedUnsavedEditsDoNotInvalidateMatching failed with:

junit.framework.AssertionFailedError: An unchanged report must reuse matching expected:<1> but was:<2>
	at com.redhat.devtools.lsp4ij.features.diagnostics.WorkspaceDiagnosticsTest.assertUnchangedMatchInvalidation(WorkspaceDiagnosticsTest.java:320)
	at com.redhat.devtools.lsp4ij.features.diagnostics.WorkspaceDiagnosticsTest.testUnrelatedUnsavedEditsDoNotInvalidateMatching(WorkspaceDiagnosticsTest.java:275)

On main (e96dee9c), running the class three times on macOS failed once, in testUnchangedReportsReuseMatchesUntilDefinitionChanges, at the same assertion.

Cause

WorkspaceDiagnosticManager reuses a match for an unchanged report only while the file's matching version is unchanged. LanguageClientImpl.workspaceDiagnosticMatchingVersion includes the stamp of the file's cached document, FileDocumentManager.getCachedDocument(file), or 0 when there is none.

assertUnchangedMatchInvalidation loads that document before the first report, to have it in the matching version: assertNotNull(FileDocumentManager.getInstance().getDocument(file)). It doesn't keep it, though, and FileDocumentManagerBase keeps an unmodified document only in a weak-value map (myDocumentCache, CollectionFactory.createConcurrentWeakValueMap()). When a garbage collection between the full report and the unchanged report clears it, the document's part of the version goes from the file's stamp to 0. The unchanged report is then matched again, and the count is 2.

For the client this is harmless, just one more match.

Expected

The test keeps the document until it ends, so that its outcome doesn't depend on when the JVM collects garbage.

Activity

  1. added a commit that references this issue on Nov 2, 2026
    fb689ea
  2. added a commit that references this issue on Nov 3, 2026
    33a35e9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions