I upgraded one of our unit test projects to use the latest HSQLDB 2.0.0-rc9 jar and encountered the following NPE:
java.lang.NullPointerException
at org.hsqldb.StatementManager.freeStatement(StatementManager.java:280)
at org.hsqldb.Session.execute(Session.java:985)
at org.hsqldb.jdbc.JDBCPreparedStatement.close(JDBCPreparedStatement.java:1981)
at org.apache.commons.dbcp.DelegatingStatement.close(DelegatingStatement.java:168)
at Test.createSchema(Test.java:41)
at Test.main(Test.java:54)
This particular traceback was from a test case that I have created to reproduce the problem.
Test test = new Test();
try {
System.out.println("begin test…");
test.createSchema();
System.out.println("end test: OK");
} catch (Exception e) {
System.out.println("end test: ERROR");
e.printStackTrace();
}
}
}
I am able to work around this problem by modifying StatementManager.freeStatement() at line 180 by only removing the entry from the sqlMap if it is not null, but this, of course, may not be the correct solution.
Thanks.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I upgraded one of our unit test projects to use the latest HSQLDB 2.0.0-rc9 jar and encountered the following NPE:
java.lang.NullPointerException
at org.hsqldb.StatementManager.freeStatement(StatementManager.java:280)
at org.hsqldb.Session.execute(Session.java:985)
at org.hsqldb.jdbc.JDBCPreparedStatement.close(JDBCPreparedStatement.java:1981)
at org.apache.commons.dbcp.DelegatingStatement.close(DelegatingStatement.java:168)
at Test.createSchema(Test.java:41)
at Test.main(Test.java:54)
This particular traceback was from a test case that I have created to reproduce the problem.
Here is the code for the test case:
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.Properties;
import javax.sql.DataSource;
import org.apache.commons.dbcp.BasicDataSourceFactory;
public class Test {
private static String SERVER_MODE_URL_PREFIX = "jdbc:hsqldb:hsql://localhost/";
private static String MEMORY_MODE_URL_PREFIX = "jdbc:hsqldb:mem:";
private boolean serverMode = false;
private DataSource dataSource = null;
private String databaseName = "CRISOP";
private String schema = "CRISOP";
public void createSchema() throws Exception {
Properties props = new Properties();
props.setProperty("driverClassName", "org.hsqldb.jdbcDriver");
props.setProperty("url",
(serverMode ? SERVER_MODE_URL_PREFIX : MEMORY_MODE_URL_PREFIX)+databaseName);
props.setProperty("username", "sa");
props.setProperty("password", "");
dataSource = BasicDataSourceFactory.createDataSource(props);
Connection con = null;
try {
con = dataSource.getConnection();
con.setAutoCommit(true);
String sql = "create schema "+schema+" authorization DBA";
PreparedStatement stmt = null;
try {
stmt = con.prepareStatement(sql);
stmt.executeUpdate();
} finally {
if (stmt!=null) stmt.close();
}
} finally {
if (con!=null) con.close();
}
}
public static void main(String args) {
Test test = new Test();
try {
System.out.println("begin test…");
test.createSchema();
System.out.println("end test: OK");
} catch (Exception e) {
System.out.println("end test: ERROR");
e.printStackTrace();
}
}
}
I am able to work around this problem by modifying StatementManager.freeStatement() at line 180 by only removing the entry from the sqlMap if it is not null, but this, of course, may not be the correct solution.
Thanks.
Thanks,
I've just fixed this. The next snapshot jar on http://hsqldb.org/support/ will include the fix.