Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Close iterators left open by CollectionDataStore getCount and getBoun…

…ds methods as per GEOT-4306
  • Loading branch information...
commit 3a6ff056da52fc99cb646f458f17be9eebe102de 1 parent a534e45
@jodygarnett jodygarnett authored
View
46 modules/library/main/src/main/java/org/geotools/data/collection/CollectionDataStore.java
@@ -20,6 +20,7 @@
import org.geotools.data.AbstractDataStore;
import org.geotools.data.DataSourceException;
+import org.geotools.data.DataUtilities;
import org.geotools.data.FeatureReader;
import org.geotools.data.Query;
import org.geotools.data.SchemaNotFoundException;
@@ -136,24 +137,27 @@ protected ReferencedEnvelope getBounds(Query query) throws SchemaNotFoundExcepti
* @param query
*/
protected ReferencedEnvelope getBoundsInternal(Query query) {
- FeatureIterator<SimpleFeature> iterator = collection.features();
ReferencedEnvelope envelope = new ReferencedEnvelope( featureType.getCoordinateReferenceSystem() );
-
- if (iterator.hasNext()) {
- int count = 1;
- Filter filter = query.getFilter();
-
- while (iterator.hasNext() && (count < query.getMaxFeatures())) {
- SimpleFeature feature = iterator.next();
-
- if (filter.evaluate(feature)) {
- count++;
- envelope.expandToInclude(((Geometry)feature.getDefaultGeometry()).getEnvelopeInternal());
+
+ FeatureIterator<SimpleFeature> iterator = collection.features();
+ try {
+ if (iterator.hasNext()) {
+ int count = 1;
+ Filter filter = query.getFilter();
+
+ while (iterator.hasNext() && (count < query.getMaxFeatures())) {
+ SimpleFeature feature = iterator.next();
+ if (filter.evaluate(feature)) {
+ count++;
+ envelope.expandToInclude(((Geometry)feature.getDefaultGeometry()).getEnvelopeInternal());
+ }
}
}
}
- return envelope;
-
+ finally {
+ iterator.close();
+ }
+ return envelope;
}
/**
@@ -165,17 +169,19 @@ protected int getCount(Query query)
if (!featureType.getTypeName().equals(featureTypeName)) {
throw new SchemaNotFoundException(featureTypeName);
}
- int count = 0;
- FeatureIterator<SimpleFeature> iterator = collection.features();
-
+ int count = 0;
+ FeatureIterator<SimpleFeature> iterator = collection.features();
+ try {
Filter filter = query.getFilter();
-
while (iterator.hasNext() && (count < query.getMaxFeatures())) {
if (filter.evaluate(iterator.next())) {
count++;
}
}
-
- return count;
+ }
+ finally {
+ iterator.close();
+ }
+ return count;
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.