mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#1889 - NPE at Str.java:16) when using DB.sqlUpdate(...).addBatch() without any bind parameters
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user