#1889 - NPE at Str.java:16) when using DB.sqlUpdate(...).addBatch() without any bind parameters

This commit is contained in:
rob bygrave
2019-12-13 13:35:54 +13:00
parent 91e7540a39
commit d4b35cb445
2 changed files with 26 additions and 2 deletions
@@ -1,6 +1,7 @@
package org.tests.batchinsert;
import io.ebean.BaseTestCase;
import io.ebean.DB;
import io.ebean.Ebean;
import io.ebean.Transaction;
import io.ebean.annotation.IgnorePlatform;
@@ -208,4 +209,21 @@ public class TestBatchInsertSimple extends BaseTestCase {
return detail;
}
@Test(expected = Test.None.class)// no exception expected
public void npe_addBatch_withoutAnyBindParams() {
try (Transaction txn = DB.beginTransaction()) {
// don't write code like this please ...
DB.sqlUpdate("update ut_master set name='DoNotDoThisPlease' where id=999999999").addBatch();
txn.commit();
}
// don't write code like the above but use bind values like:
try (Transaction txn = DB.beginTransaction()) {
DB.sqlUpdate("update ut_master set name=? where id=?")
.setParams("DoNotDoThisPlease", 999999999)
.addBatch();
txn.commit();
}
}
}