From 4d34c9e868f7d8eea6f9a930a06684fb17632dcf Mon Sep 17 00:00:00 2001 From: Rob Bygrave Date: Thu, 21 Oct 2021 12:02:42 +1300 Subject: [PATCH] #2424 Change error for transaction register(Callback) when no active transaction from PersistenceException to NullPointerException Ah ok, so in being more strict on null for currentTransaction() that shows up the code that registers transaction callbacks as checking for null and throwing PersistenceException. This is inconsistent with LOTS of other methods that use currentTransaction() and would result in NPE. The concept here is that PersistenceException for this case isn't better than NPE and NPE is actually more consistence wrt using currentTransaction(). --- .../java/org/tests/transaction/TestTransactionCallback.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ebean-test/src/test/java/org/tests/transaction/TestTransactionCallback.java b/ebean-test/src/test/java/org/tests/transaction/TestTransactionCallback.java index 3135fa42f..cce91acc0 100644 --- a/ebean-test/src/test/java/org/tests/transaction/TestTransactionCallback.java +++ b/ebean-test/src/test/java/org/tests/transaction/TestTransactionCallback.java @@ -72,12 +72,12 @@ public class TestTransactionCallback extends BaseTestCase { @Test public void test_noActiveTransaction() { - assertThrows(PersistenceException.class, () -> DB.register(new MyCallback())); + assertThrows(NullPointerException.class, () -> DB.register(new MyCallback())); } @Test public void test_noActiveTransaction_withDatabase() { - assertThrows(PersistenceException.class, () -> DB.getDefault().register(new MyCallback())); + assertThrows(NullPointerException.class, () -> DB.getDefault().register(new MyCallback())); } class MyCallback extends TransactionCallbackAdapter {