Skip to content

Commit

Permalink
Runtime: Fix NullpointerException in connection commit introduced in c…
Browse files Browse the repository at this point in the history
  • Loading branch information
lawesson committed Sep 9, 2016
1 parent 443ae7a commit 96b835b
Showing 1 changed file with 12 additions and 7 deletions.
Expand Up @@ -55,7 +55,7 @@ public final class AsynchronousQueryResultImpl<T> implements AsynchronousQueryRe
private Function<ResultSet, T> rsMapper;
private final Supplier<Connection> connectionSupplier;
private ParallelStrategy parallelStrategy;
private Connection connection;
private Connection connection; // null allowed if the stream() method is not run
private PreparedStatement ps;
private ResultSet rs;
private State state;
Expand All @@ -71,8 +71,8 @@ public AsynchronousQueryResultImpl(
Supplier<Connection> connectionSupplier
) {
setSql(sql); // requireNonNull in setter
setValues(values);
setRsMapper(rsMapper);
setValues(values); // requireNonNull in setter
setRsMapper(rsMapper); // requireNonNull in setter
this.connectionSupplier = requireNonNull(connectionSupplier);
parallelStrategy = ParallelStrategy.DEFAULT;
setState(State.INIT);
Expand Down Expand Up @@ -103,16 +103,21 @@ public Stream<T> stream() {
public void close() {
closeSilently(rs);
closeSilently(ps);
commitSilently(connection);
setState(State.CLOSED);
}

private void commitSilently(Connection connection) {
try {
connection.commit();
if (connection != null) {
connection.commit();
}
} catch (SQLException e) {
LOGGER.error(e, "Failed to commit connection upon close");
}
closeSilently(connection);
setState(State.CLOSED);
}

protected void closeSilently(final AutoCloseable closeable) {
private void closeSilently(final AutoCloseable closeable) {
try {
if (closeable != null) {
closeable.close();
Expand Down

0 comments on commit 96b835b

Please sign in to comment.