From 5eebe56dd1fd478618e5a09b7bef5f389eb2d11f Mon Sep 17 00:00:00 2001 From: Brett Wooldridge Date: Sun, 6 Mar 2016 17:37:10 +0900 Subject: [PATCH] Fixes #591 Synchronise the track statement method, and clearing of the tracked statement list. --- src/main/java/com/zaxxer/hikari/pool/ProxyConnection.java | 6 ++++-- src/main/java/com/zaxxer/hikari/util/FastList.java | 4 ++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/zaxxer/hikari/pool/ProxyConnection.java b/src/main/java/com/zaxxer/hikari/pool/ProxyConnection.java index b4fb824d..1ad3a404 100644 --- a/src/main/java/com/zaxxer/hikari/pool/ProxyConnection.java +++ b/src/main/java/com/zaxxer/hikari/pool/ProxyConnection.java @@ -182,7 +182,7 @@ public abstract class ProxyConnection implements Connection leakTask.cancel(); } - private final T trackStatement(final T statement) + private final synchronized T trackStatement(final T statement) { openStatements.add(statement); @@ -205,7 +205,9 @@ public abstract class ProxyConnection implements Connection } } - openStatements.clear(); + synchronized (this) { + openStatements.clear(); + } } } diff --git a/src/main/java/com/zaxxer/hikari/util/FastList.java b/src/main/java/com/zaxxer/hikari/util/FastList.java index 8eb9347f..6b6c6dd5 100644 --- a/src/main/java/com/zaxxer/hikari/util/FastList.java +++ b/src/main/java/com/zaxxer/hikari/util/FastList.java @@ -184,6 +184,10 @@ public final class FastList extends ArrayList @Override public T remove(int index) { + if (size == 0) { + return null; + } + final T old = elementData[index]; final int numMoved = size - index - 1;