Skip to content

Commit 7787b9e

Browse files
committed
Fixed NPE in PooledSQL
1 parent 467f48d commit 7787b9e

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/main/java/org/javawebstack/orm/connection/pool/PooledSQL.java

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ public class PooledSQL implements SQL, AutoCloseable {
1616
private boolean closed;
1717

1818
public PooledSQL(SQLPool pool, SQL connection) {
19+
if(connection == null)
20+
throw new IllegalArgumentException("connection can not be null");
1921
this.pool = pool;
2022
this.connection = connection;
2123
}

src/main/java/org/javawebstack/orm/connection/pool/SQLPool.java

+9-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.javawebstack.orm.connection.SQL;
55

66
import java.util.*;
7+
import java.util.concurrent.BlockingQueue;
78
import java.util.concurrent.LinkedBlockingQueue;
89
import java.util.function.Supplier;
910

@@ -12,7 +13,7 @@ public class SQLPool {
1213
private final PoolScaling scaling;
1314
private final Supplier<SQL> supplier;
1415
private final List<SQL> connections = new ArrayList<>();
15-
private final Queue<SQL> connectionQueue = new LinkedBlockingQueue<>();
16+
private final BlockingQueue<SQL> connectionQueue = new LinkedBlockingQueue<>();
1617
private final Set<QueryLogger> loggers = new HashSet<>();
1718
private boolean closing;
1819
private PoolQueryLogger queryLogger = new PoolQueryLogger();
@@ -31,9 +32,13 @@ public PooledSQL get() {
3132
if(closing)
3233
throw new IllegalStateException("Pool has already been closed");
3334
scale();
34-
SQL sql = connectionQueue.poll();
35-
scale();
36-
return new PooledSQL(this, sql);
35+
try {
36+
SQL sql = connectionQueue.take();
37+
scale();
38+
return new PooledSQL(this, sql);
39+
} catch (InterruptedException e) {
40+
throw new RuntimeException(e);
41+
}
3742
}
3843

3944
public void release(SQL sql) {

0 commit comments

Comments
 (0)