Fix some issues found by Idea inspections

pull/307/head
Mikhail Mazurskiy 10 years ago
parent 6ab6954641
commit ed09efc652

@ -142,6 +142,7 @@ public class HikariDataSource extends HikariConfig implements DataSource, Closea
}
/** {@inheritDoc} */
@Override
public java.util.logging.Logger getParentLogger() throws SQLFeatureNotSupportedException
{
throw new SQLFeatureNotSupportedException();

@ -85,7 +85,7 @@ public class HikariJNDIFactory implements ObjectFactory
String jndiName = properties.getProperty("dataSourceJNDI");
DataSource jndiDS = (DataSource) context.lookup(jndiName);
if (jndiDS == null) {
context = (Context) (new InitialContext());
context = new InitialContext();
jndiDS = (DataSource) context.lookup(jndiName);
}

@ -24,7 +24,7 @@ import com.zaxxer.hikari.pool.PoolBagEntry;
*
* @author Brett Wooldridge
*/
public class MetricsTracker
public class MetricsTracker implements AutoCloseable
{
public static final MetricsContext NO_CONTEXT = new MetricsContext();
@ -44,6 +44,7 @@ public class MetricsTracker
{
}
@Override
public void close()
{
}

@ -352,6 +352,7 @@ public class HikariPool implements HikariPoolMBean, IBagStateListener
{
class AddConnection implements Runnable
{
@Override
public void run()
{
long sleepBackoff = 200L;
@ -459,6 +460,7 @@ public class HikariPool implements HikariPoolMBean, IBagStateListener
}
closeConnectionExecutor.execute(new Runnable() {
@Override
public void run() {
poolUtils.quietlyCloseConnection(connection, closureReason);
}
@ -473,7 +475,7 @@ public class HikariPool implements HikariPoolMBean, IBagStateListener
/**
* Create and add a single connection to the pool.
*/
private final boolean addConnection()
private boolean addConnection()
{
// Speculative increment of totalConnections with expectation of success
if (totalConnections.incrementAndGet() > configuration.getMaximumPoolSize()) {
@ -524,6 +526,7 @@ public class HikariPool implements HikariPoolMBean, IBagStateListener
if (connectionsToAdd > 0 && LOGGER.isDebugEnabled()) {
addConnectionExecutor.execute(new Runnable() {
@Override
public void run() {
logPoolState("After fill ");
}
@ -569,8 +572,6 @@ public class HikariPool implements HikariPoolMBean, IBagStateListener
/**
* Attempt to abort() active connections, or close() them.
*
* @throws InterruptedException
*/
private void abortActiveConnections(final ExecutorService assassinExecutor)
{

@ -44,7 +44,7 @@ public class LeakTask implements Runnable
{
NO_LEAK = new LeakTask() {
@Override
public void cancel() {};
public void cancel() {}
@Override
public LeakTask start(final PoolBagEntry bagEntry)

@ -47,6 +47,7 @@ public final class PoolBagEntry implements IConcurrentBagEntry
final long maxLifetime = pool.configuration.getMaxLifetime();
if (maxLifetime > 0) {
endOfLife = pool.houseKeepingExecutorService.schedule(new Runnable() {
@Override
public void run()
{
// If we can reserve it, close it

@ -27,7 +27,7 @@ public final class PoolUtilities
private Executor netTimeoutExecutor;
private String poolName;
private final String poolName;
private volatile boolean isValidChecked;
private volatile boolean isValidSupported;
private boolean isNetworkTimeoutSupported;
@ -63,7 +63,7 @@ public final class PoolUtilities
}
}
catch (Throwable e) {
LOGGER.debug("Exception closing connection {} in pool {}{}", connection.toString(), poolName, addendum, e);
LOGGER.debug("Exception closing connection {} in pool {}{}", connection, poolName, addendum, e);
}
}
@ -78,16 +78,12 @@ public final class PoolUtilities
public void executeSql(final Connection connection, final String sql, final boolean isAutoCommit) throws SQLException
{
if (sql != null) {
Statement statement = connection.createStatement();
try {
try (Statement statement = connection.createStatement()) {
statement.execute(sql);
if (!isAutoCommit) {
connection.commit();
}
}
finally {
statement.close();
}
}
}
@ -272,7 +268,7 @@ public final class PoolUtilities
command.run();
}
catch (Throwable t) {
LOGGER.debug("Exception executing {}", command.toString(), t);
LOGGER.debug("Exception executing {}", command, t);
}
}
}

@ -112,8 +112,8 @@ public abstract class ConnectionProxy implements IHikariConnectionProxy
boolean isForceClose = sqlState.startsWith("08") | SQL_ERRORS.contains(sqlState);
if (isForceClose) {
bagEntry.evicted = true;
LOGGER.warn("Connection {} ({}) marked as broken because of SQLSTATE({}), ErrorCode({}).", delegate.toString(),
parentPool.toString(), sqlState, sqle.getErrorCode(), sqle);
LOGGER.warn("Connection {} ({}) marked as broken because of SQLSTATE({}), ErrorCode({}).", delegate,
parentPool, sqlState, sqle.getErrorCode(), sqle);
}
else {
SQLException nse = sqle.getNextException();
@ -144,7 +144,7 @@ public abstract class ConnectionProxy implements IHikariConnectionProxy
// Internal methods
// ***********************************************************************
private final <T extends Statement> T trackStatement(final T statement)
private <T extends Statement> T trackStatement(final T statement)
{
lastAccessNano = System.nanoTime();
openStatements.add(statement);
@ -152,7 +152,7 @@ public abstract class ConnectionProxy implements IHikariConnectionProxy
return statement;
}
private final void resetConnectionState() throws SQLException
private void resetConnectionState() throws SQLException
{
if (isReadOnlyDirty) {
delegate.setReadOnly(parentPool.isReadOnly);

@ -47,7 +47,7 @@ import com.zaxxer.hikari.util.ClassLoaderUtils;
*/
public final class JavassistProxyFactory
{
private ClassPool classPool;
private final ClassPool classPool;
static {
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
@ -224,7 +224,7 @@ public final class JavassistProxyFactory
paramTypes.add(toJavaClass(pt));
}
return intf.getDeclaredMethod(intfMethod.getName(), paramTypes.toArray(new Class[0])).toString().contains("default ");
return intf.getDeclaredMethod(intfMethod.getName(), paramTypes.toArray(new Class[paramTypes.size()])).toString().contains("default ");
}
private Class<?> toJavaClass(CtClass cls) throws Exception

@ -52,7 +52,7 @@ import org.slf4j.LoggerFactory;
*
* @param <T> the templated type to store in the bag
*/
public class ConcurrentBag<T extends IConcurrentBagEntry>
public class ConcurrentBag<T extends IConcurrentBagEntry> implements AutoCloseable
{
private static final Logger LOGGER = LoggerFactory.getLogger(ConcurrentBag.class);
@ -152,7 +152,7 @@ public class ConcurrentBag<T extends IConcurrentBagEntry>
synchronizer.releaseShared(sequence.incrementAndGet());
}
else {
LOGGER.warn("Attempt to remove an object from the bag that does not exist: {}", bagEntry.toString());
LOGGER.warn("Attempt to remove an object from the bag that does not exist: {}", bagEntry);
}
}
@ -184,13 +184,13 @@ public class ConcurrentBag<T extends IConcurrentBagEntry>
public boolean remove(final T bagEntry)
{
if (!bagEntry.state().compareAndSet(STATE_IN_USE, STATE_REMOVED) && !bagEntry.state().compareAndSet(STATE_RESERVED, STATE_REMOVED) && !closed) {
LOGGER.warn("Attempt to remove an object from the bag that was not borrowed or reserved: {}", bagEntry.toString());
LOGGER.warn("Attempt to remove an object from the bag that was not borrowed or reserved: {}", bagEntry);
return false;
}
final boolean removed = sharedList.remove(bagEntry);
if (!removed && !closed) {
LOGGER.warn("Attempt to remove an object from the bag that does not exist: {}", bagEntry.toString());
LOGGER.warn("Attempt to remove an object from the bag that does not exist: {}", bagEntry);
}
return removed;
}
@ -198,6 +198,7 @@ public class ConcurrentBag<T extends IConcurrentBagEntry>
/**
* Close the bag to further adds.
*/
@Override
public void close()
{
closed = true;
@ -255,7 +256,7 @@ public class ConcurrentBag<T extends IConcurrentBagEntry>
synchronizer.releaseShared(checkInSeq);
}
else {
LOGGER.warn("Attempt to relinquish an object to the bag that was not reserved: {}", bagEntry.toString());
LOGGER.warn("Attempt to relinquish an object to the bag that was not reserved: {}", bagEntry);
}
}

@ -19,8 +19,8 @@ import java.util.concurrent.ThreadFactory;
public class DefaultThreadFactory implements ThreadFactory {
private String threadName;
private boolean daemon;
private final String threadName;
private final boolean daemon;
public DefaultThreadFactory(String threadName, boolean daemon) {
this.threadName = threadName;

@ -113,6 +113,7 @@ public final class DriverDataSource implements DataSource
return DriverManager.getLoginTimeout();
}
@Override
public java.util.logging.Logger getParentLogger() throws SQLFeatureNotSupportedException
{
return driver.getParentLogger();

@ -209,7 +209,7 @@ public class TestConnections
Assert.assertTrue("Connection should have closed", connection.isClosed());
Assert.assertFalse("Connection should have closed", connection.isValid(5));
Assert.assertTrue("Expected to contain ClosedConnection, but was " + connection.toString(), connection.toString().contains("ClosedConnection"));
Assert.assertTrue("Expected to contain ClosedConnection, but was " + connection, connection.toString().contains("ClosedConnection"));
connection.close();
}

Loading…
Cancel
Save