From 1bb8a4baf9c6f222c3a00266d679dd7f714fcb6a Mon Sep 17 00:00:00 2001 From: Andrey Loskutov Date: Thu, 9 Oct 2025 14:51:03 +0200 Subject: [PATCH] Remove document listener from *old* document on setDocument() UpdateDocumentListener is added to document but not always removed in ProjectionViewer, regression introduced by commit https://github.com/eclipse-platform/eclipse.platform.ui/commit/1848058a52102b5deff39427365e56fe882656b3 This fixes remaining possible leak, where *multiple* documents were used in ProjectionViewer. See https://github.com/eclipse-jdt/eclipse.jdt.ui/issues/2532 --- .../source/projection/ProjectionViewer.java | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/bundles/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/ProjectionViewer.java b/bundles/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/ProjectionViewer.java index a99a85541dd..576c0212ec9 100644 --- a/bundles/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/ProjectionViewer.java +++ b/bundles/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/ProjectionViewer.java @@ -400,6 +400,7 @@ public void setDocument(IDocument document, IAnnotationModel annotationModel, in } if (fProjectionAnnotationModel != null) { + removeDocumentUpdateListener(); wasProjectionEnabled= removeProjectionAnnotationModel(getVisualAnnotationModel()) != null; fProjectionAnnotationModel= null; } @@ -413,6 +414,15 @@ public void setDocument(IDocument document, IAnnotationModel annotationModel, in } + private void removeDocumentUpdateListener() { + if (fUpdateDocumentListener != null) { + IDocument document= getDocument(); + if (document != null) { + document.removeDocumentListener(fUpdateDocumentListener); + } + } + } + @Override protected IAnnotationModel createVisualAnnotationModel(IAnnotationModel annotationModel) { IAnnotationModel model= super.createVisualAnnotationModel(annotationModel); @@ -554,10 +564,7 @@ public final void disableProjection() { super.setVisibleRegion(fVisibleRegionDuringProjection.getOffset(), fVisibleRegionDuringProjection.getLength()); fVisibleRegionDuringProjection= null; } - IDocument document= getDocument(); - if (document != null) { - document.removeDocumentListener(fUpdateDocumentListener); - } + removeDocumentUpdateListener(); } } @@ -1480,12 +1487,7 @@ private boolean willAutoExpand(Position position, int offset, int length) { @Override protected void handleDispose() { fWasProjectionEnabled= false; - if (fUpdateDocumentListener != null) { - IDocument document= getDocument(); - if (document != null) { - document.removeDocumentListener(fUpdateDocumentListener); - } - } + removeDocumentUpdateListener(); super.handleDispose(); }