From 8e677aa92ed5a883d40182bf277532e02937556e Mon Sep 17 00:00:00 2001 From: moparisthebest Date: Thu, 6 Sep 2018 01:15:20 -0400 Subject: [PATCH] Fix ResultSet leak in toStream --- .../java/com/moparisthebest/jdbc/util/ResultSetIterable.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/com/moparisthebest/jdbc/util/ResultSetIterable.java b/common/src/main/java/com/moparisthebest/jdbc/util/ResultSetIterable.java index 9be78e1..f897fde 100644 --- a/common/src/main/java/com/moparisthebest/jdbc/util/ResultSetIterable.java +++ b/common/src/main/java/com/moparisthebest/jdbc/util/ResultSetIterable.java @@ -21,7 +21,7 @@ import static com.moparisthebest.jdbc.TryClose.tryClose; * This has some special semantics the caller must be aware of though: *

* 1. It has to be closed in a finally just like a ResultSet so it can close it's underlying ResultSet - * 2. Call to .iterator() just returns this, meaning you can only loop over it once, if you need to loop multiple times get a List or something + * 2. The .iterator() implementation just returns this, meaning you can only loop over it once, if you need to loop multiple times get a List or something * 3. This guarantees that the ResultSet/Calendar you send into this class with the ResultSetToObject will be the only * instances sent into the ResultSetToObject.toObject() method, so if you do fancy initialization of some sort you can * do it in the constructor based on those instances, or once on the first call to .toObject() and cache it forever. @@ -79,7 +79,8 @@ public class ResultSetIterable implements Iterable, Iterator, Closeable public static Stream getStream(final ResultSet rs, final ResultSetToObject rsto, final Calendar cal) { final Stream ret; if (rsto == null) { - // todo: static object for this? don't forget to close resultset if so + tryClose(rs); // have to do this here... + // todo: static object for this? return (Stream) StreamSupport.stream(Spliterators.emptySpliterator(), false); } else { final ResultSetIterable rsi = new ResultSetIterable(rs, rsto, cal);