Fixing a NPE case after Duplciate detection If a Transaction wasn't created, the case for duplciate Detection would cancel a transaction that never happened and it would get a NPE instead of a TX Exception.
It wasn't a big deal as the client got an exception anyways and the users were able to cancel in that case but the message sent was a string containing just "Null". this will fix it with a proper handling Project: http://git-wip-us.apache.org/repos/asf/activemq-6/repo Commit: http://git-wip-us.apache.org/repos/asf/activemq-6/commit/2154c754 Tree: http://git-wip-us.apache.org/repos/asf/activemq-6/tree/2154c754 Diff: http://git-wip-us.apache.org/repos/asf/activemq-6/diff/2154c754 Branch: refs/heads/master Commit: 2154c754c850568988251d8c04ebfabdd41d9aee Parents: 41b823b Author: Clebert Suconic <[email protected]> Authored: Thu Apr 9 15:00:06 2015 -0400 Committer: Clebert Suconic <[email protected]> Committed: Thu Apr 9 15:03:47 2015 -0400 ---------------------------------------------------------------------- .../apache/activemq/core/transaction/impl/TransactionImpl.java | 5 ++++- .../activemq/tests/integration/DuplicateDetectionTest.java | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/activemq-6/blob/2154c754/activemq-server/src/main/java/org/apache/activemq/core/transaction/impl/TransactionImpl.java ---------------------------------------------------------------------- diff --git a/activemq-server/src/main/java/org/apache/activemq/core/transaction/impl/TransactionImpl.java b/activemq-server/src/main/java/org/apache/activemq/core/transaction/impl/TransactionImpl.java index 2511e4e..4697fba 100644 --- a/activemq-server/src/main/java/org/apache/activemq/core/transaction/impl/TransactionImpl.java +++ b/activemq-server/src/main/java/org/apache/activemq/core/transaction/impl/TransactionImpl.java @@ -167,7 +167,10 @@ public class TransactionImpl implements Transaction // so we reset it now beforeRollback(); afterRollback(); - operations.clear(); + if (operations != null) + { + operations.clear(); + } throw exception; } else http://git-wip-us.apache.org/repos/asf/activemq-6/blob/2154c754/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/DuplicateDetectionTest.java ---------------------------------------------------------------------- diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/DuplicateDetectionTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/DuplicateDetectionTest.java index 3fe9ad0..486a552 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/DuplicateDetectionTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/DuplicateDetectionTest.java @@ -1245,6 +1245,7 @@ public class DuplicateDetectionTest extends ServiceTestBase } catch (XAException expected) { + assertTrue(expected.getCause().toString().contains("DUPLICATE_ID_REJECTED")); } session.rollback(xid2);
