Skip to content

Commit 7bd0604

Browse files
committed
Avoid "java.util.NoSuchElementException: No such Feature exsists" errors when calling Layer.first() with a Filter that returns no Features. Return null instead.
1 parent d81f4aa commit 7bd0604

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/main/groovy/geoscript/layer/Layer.groovy

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -658,8 +658,11 @@ class Layer {
658658
}
659659
Map params = options.get("params")
660660
Cursor c = getCursor(filter: filter, sort: sort, params: params)
661-
Feature f = c.next()
662-
c.close()
661+
Feature f = null
662+
if (c.hasNext()) {
663+
f = c.next()
664+
c.close()
665+
}
663666
f
664667
}
665668

src/test/groovy/geoscript/layer/LayerTestCase.groovy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,7 @@ class LayerTestCase {
782782
assertEquals "House 1", layer.first(sort: "price ASC").get("name")
783783
assertEquals "House 2", layer.first(filter: "price > 13 AND price < 14").get("name")
784784
assertEquals "House 3", layer.first(filter: "price > 13 AND price < 15", sort: "price DESC").get("name")
785+
assertNull layer.first(filter: "price < 10")
785786
}
786787

787788
@Test void transform() {

0 commit comments

Comments
 (0)