diff --git a/platform/core-impl/src/com/intellij/openapi/application/TransactionGuardImpl.java b/platform/core-impl/src/com/intellij/openapi/application/TransactionGuardImpl.java index 1002f305b867..e7f37eadea31 100644 --- a/platform/core-impl/src/com/intellij/openapi/application/TransactionGuardImpl.java +++ b/platform/core-impl/src/com/intellij/openapi/application/TransactionGuardImpl.java @@ -83,8 +83,15 @@ public class TransactionGuardImpl extends TransactionGuard { } @NotNull - private Queue getQueue(@Nullable TransactionIdImpl prevTransaction) { - return prevTransaction == null ? myQueue : prevTransaction.myQueue; + private Queue getQueue(@Nullable TransactionIdImpl transaction) { + if (transaction == null) { + return myQueue; + } + if (myCurrentTransaction != null && transaction.myStartCounter > myCurrentTransaction.myStartCounter) { + // transaction is finished already, it makes no sense to add to its queue + return myCurrentTransaction.myQueue; + } + return transaction.myQueue; } private void pollQueueLater() { diff --git a/platform/platform-tests/testSrc/com/intellij/application/TransactionTest.groovy b/platform/platform-tests/testSrc/com/intellij/application/TransactionTest.groovy index 13bc5d246db6..70a4d91abbd7 100644 --- a/platform/platform-tests/testSrc/com/intellij/application/TransactionTest.groovy +++ b/platform/platform-tests/testSrc/com/intellij/application/TransactionTest.groovy @@ -160,4 +160,20 @@ class TransactionTest extends LightPlatformTestCase { } } + public void "test submit with finished transaction id"() { + TransactionGuard.submitTransaction testRootDisposable, { + log << '1' + TransactionId id = null + TransactionGuard.submitTransaction testRootDisposable, { + log << '2' + id = guard.contextTransaction + } + SwingUtilities.invokeLater { + guard.submitMergeableTransaction testRootDisposable, id, { log << '3' } + } + UIUtil.dispatchAllInvocationEvents() + assert log == ['1', '2', '3'] + } + } + }