#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
@@ -13,14 +13,20 @@ public class Str {
public static String add(String s0, String s1, String... args) {
// determine a decent buffer size
int len = 16 + s0.length() + s1.length();
int len = 16 + s0.length();
if (s1 != null) {
len += s1.length();
}
for (String arg1 : args) {
len += (arg1 == null) ? 0 : arg1.length();
}
// append all the strings into the buffer
StringBuilder sb = new StringBuilder(len);
sb.append(s0).append(s1);
sb.append(s0);
if (s1 != null) {
sb.append(s1);
}
for (String arg : args) {
if (arg != null) {
sb.append(arg);
@@ -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();
}
}
}