#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().
This commit is contained in:
Rob Bygrave committed 2021-10-21 12:02:42 +13:00
1 parent 5178b76431
commit 4d34c9e868
1 file changed
+2 -2
@@ -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 {