Skip to content

Commit

Permalink
Fixes #1141 do not throw SQLException when calling isClosed() or clos…
Browse files Browse the repository at this point in the history
…e() on a already closed Connection, as per JDBC specification.
  • Loading branch information
brettwooldridge committed May 19, 2018
1 parent 8921bb0 commit 5607d8b
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions src/main/java/com/zaxxer/hikari/pool/ProxyConnection.java
Expand Up @@ -16,26 +16,18 @@

package com.zaxxer.hikari.pool;

import static com.zaxxer.hikari.util.ClockSource.currentTime;
import com.zaxxer.hikari.util.FastList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Savepoint;
import java.sql.Statement;
import java.sql.Wrapper;
import java.sql.*;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.Executor;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.zaxxer.hikari.util.FastList;
import static com.zaxxer.hikari.util.ClockSource.currentTime;

/**
* This is the proxy class for java.sql.Connection.
Expand Down Expand Up @@ -264,6 +256,7 @@ public final void close() throws SQLException

/** {@inheritDoc} */
@Override
@SuppressWarnings("RedundantThrows")
public boolean isClosed() throws SQLException
{
return (delegate == ClosedConnection.CLOSED_CONNECTION);
Expand Down Expand Up @@ -447,7 +440,7 @@ public void setSchema(String schema) throws SQLException
@Override
public final boolean isWrapperFor(Class<?> iface) throws SQLException
{
return iface.isInstance(delegate) || (delegate instanceof Wrapper && delegate.isWrapperFor(iface));
return iface.isInstance(delegate) || (delegate != null && delegate.isWrapperFor(iface));
}

/** {@inheritDoc} */
Expand All @@ -458,7 +451,7 @@ public final <T> T unwrap(Class<T> iface) throws SQLException
if (iface.isInstance(delegate)) {
return (T) delegate;
}
else if (delegate instanceof Wrapper) {
else if (delegate != null) {
return delegate.unwrap(iface);
}

Expand All @@ -477,12 +470,18 @@ private static Connection getClosedConnection()
{
InvocationHandler handler = (proxy, method, args) -> {
final String methodName = method.getName();
if ("abort".equals(methodName)) {
return Void.TYPE;
if ("isClosed".equals(methodName)) {
return Boolean.TRUE;
}
else if ("isValid".equals(methodName)) {
return Boolean.FALSE;
}
if ("abort".equals(methodName)) {
return Void.TYPE;
}
if ("close".equals(methodName)) {
return Void.TYPE;
}
else if ("toString".equals(methodName)) {
return ClosedConnection.class.getCanonicalName();
}
Expand Down

0 comments on commit 5607d8b

Please sign in to comment.