Unverified 提交 84092ec5 authored 作者: Andrei Tokar's avatar Andrei Tokar 提交者: GitHub

Merge pull request #1353 from h2database/crash-api

Crash api
......@@ -170,6 +170,11 @@ public abstract class Prepared {
* @throws DbException if any parameter has not been set
*/
protected void checkParameters() {
if (persistedObjectId < 0) {
// restore original persistedObjectId on Command re-run
// i.e. due to concurrent update
persistedObjectId = -persistedObjectId - 1;
}
if (parameters != null) {
for (Parameter param : parameters) {
param.checkSet();
......@@ -268,7 +273,7 @@ public abstract class Prepared {
} else if (id < 0) {
throw DbException.throwInternalError("Prepared.getObjectId() was called before");
}
persistedObjectId = -1;
persistedObjectId = -persistedObjectId - 1; // while negative, it can be restored later
return id;
}
......
......@@ -102,6 +102,9 @@ public class JdbcBlob extends JdbcLob implements Blob {
*/
@Override
public int setBytes(long pos, byte[] bytes) throws SQLException {
if (bytes == null) {
throw new NullPointerException();
}
try {
if (isDebugEnabled()) {
debugCode("setBytes("+pos+", "+quoteBytes(bytes)+");");
......@@ -129,6 +132,9 @@ public class JdbcBlob extends JdbcLob implements Blob {
@Override
public int setBytes(long pos, byte[] bytes, int offset, int len)
throws SQLException {
if (bytes == null) {
throw new NullPointerException();
}
try {
if (isDebugEnabled()) {
debugCode("setBytes(" + pos + ", " + quoteBytes(bytes) + ", " + offset + ", " + len + ");");
......
......@@ -383,6 +383,7 @@ public class TestCrashAPI extends TestDb implements Runnable {
boolean isDefault =
(m.getModifiers() & (Modifier.ABSTRACT | Modifier.PUBLIC | Modifier.STATIC)) == Modifier.PUBLIC
&& m.getDeclaringClass().isInterface();
boolean allowNPE = isDefault || o instanceof Blob && "setBytes".equals(m.getName());
Class<?>[] paramClasses = m.getParameterTypes();
Object[] params = new Object[paramClasses.length];
for (int i = 0; i < params.length; i++) {
......@@ -398,7 +399,7 @@ public class TestCrashAPI extends TestDb implements Runnable {
TestBase.logError("error", e);
} catch (InvocationTargetException e) {
Throwable t = e.getTargetException();
printIfBad(seed, id, objectId, t, isDefault);
printIfBad(seed, id, objectId, t, allowNPE);
}
if (result == null) {
return null;
......@@ -414,7 +415,7 @@ public class TestCrashAPI extends TestDb implements Runnable {
printIfBad(seed, id, objectId, t, false);
}
private void printIfBad(int seed, int id, int objectId, Throwable t, boolean isDefault) {
private void printIfBad(int seed, int id, int objectId, Throwable t, boolean allowNPE) {
if (t instanceof BatchUpdateException) {
// do nothing
} else if (t.getClass().getName().contains("SQLClientInfoException")) {
......@@ -438,8 +439,8 @@ public class TestCrashAPI extends TestDb implements Runnable {
// General error [HY000]
printError(seed, id, s);
}
} else if (isDefault && t instanceof NullPointerException) {
// do nothing, default methods may throw this exception
} else if (allowNPE && t instanceof NullPointerException) {
// do nothing, this methods may throw this exception
} else {
printError(seed, id, t);
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论