From d6374a3b4ba24e1118ec35e4cdcb3e26bbb2a138 Mon Sep 17 00:00:00 2001 From: peter Date: Tue, 5 Apr 2016 12:49:06 +0200 Subject: [PATCH] fix submitting with finished transaction id --- .../application/TransactionGuardImpl.java | 11 +++++++++-- .../intellij/application/TransactionTest.groovy | 16 ++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) 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'] + } + } + }