diff --git a/platform/core-impl/src/com/intellij/openapi/editor/impl/DocumentImpl.java b/platform/core-impl/src/com/intellij/openapi/editor/impl/DocumentImpl.java index 6a96922ae659..f23901f1b2e1 100644 --- a/platform/core-impl/src/com/intellij/openapi/editor/impl/DocumentImpl.java +++ b/platform/core-impl/src/com/intellij/openapi/editor/impl/DocumentImpl.java @@ -56,6 +56,7 @@ public class DocumentImpl extends UserDataHolderBase implements DocumentEx { private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.editor.impl.DocumentImpl"); public static boolean CHECK_DOCUMENT_CONSISTENCY = ApplicationManager.getApplication() != null && ApplicationManager.getApplication().isUnitTestMode(); + private final Ref myCachedDocumentListeners = Ref.create(null); private final List myDocumentListeners = ContainerUtil.createLockFreeCopyOnWriteList(); private final RangeMarkerTree myRangeMarkers = new RangeMarkerTree(this); private final List myGuardedBlocks = new ArrayList(); @@ -70,7 +71,6 @@ public class DocumentImpl extends UserDataHolderBase implements DocumentEx { private volatile long myModificationStamp; private final PropertyChangeSupport myPropertyChangeSupport = new PropertyChangeSupport(this); - private final Ref myCachedDocumentListeners = Ref.create(null); private final List myReadOnlyListeners = ContainerUtil.createLockFreeCopyOnWriteList(); private int myCheckGuardedBlocks = 0; @@ -713,9 +713,7 @@ public class DocumentImpl extends UserDataHolderBase implements DocumentEx { @Override public void addDocumentListener(@NotNull DocumentListener listener) { - if (myCachedDocumentListeners != null) { - myCachedDocumentListeners.set(null); - } + myCachedDocumentListeners.set(null); LOG.assertTrue(!myDocumentListeners.contains(listener), "Already registered: " + listener); boolean added = myDocumentListeners.add(listener); @@ -729,12 +727,13 @@ public class DocumentImpl extends UserDataHolderBase implements DocumentEx { } private static class DocumentListenerDisposable implements Disposable { + private final DocumentListener myListener; + private final Ref myCachedDocumentListenersRef; + private final List myDocumentListeners; - private DocumentListener myListener; - private Ref myCachedDocumentListenersRef; - private List myDocumentListeners; - - public DocumentListenerDisposable(DocumentListener listener, Ref cachedDocumentListenersRef, List documentListeners) { + public DocumentListenerDisposable(@NotNull DocumentListener listener, + @NotNull Ref cachedDocumentListenersRef, + @NotNull List documentListeners) { myListener = listener; myCachedDocumentListenersRef = cachedDocumentListenersRef; myDocumentListeners = documentListeners; @@ -751,12 +750,10 @@ public class DocumentImpl extends UserDataHolderBase implements DocumentEx { doRemoveDocumentListener(listener, myCachedDocumentListeners, myDocumentListeners); } - private static void doRemoveDocumentListener(DocumentListener listener, - Ref cachedDocumentListenersRef, - List documentListeners) { - if (cachedDocumentListenersRef != null) { - cachedDocumentListenersRef.set(null); - } + private static void doRemoveDocumentListener(@NotNull DocumentListener listener, + @NotNull Ref cachedDocumentListenersRef, + @NotNull List documentListeners) { + cachedDocumentListenersRef.set(null); boolean success = documentListeners.remove(listener); if (!success) { LOG.error("Can't remove document listener (" + listener + "). Registered cachedDocumentListenersRef: " + documentListeners);