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