SelectionLab NPE

Description

From email:

While running the SelectionLab example with 11-RC1, I get a null pointer exception when I use the ‘select tool’ to click on a feature. Specifically, the exception is raised on the call to selectedFeatures.features(); I’ve traced it to the ExtractBoundsFilterVisitor.visit function returning null. Does this look like a bug?

from SelectionLab.java:

AffineTransform screenToWorld = mapFrame.getMapPane().getScreenToWorldTransform();
Rectangle2D worldRect = screenToWorld.createTransformedShape(screenRect).getBounds2D();
ReferencedEnvelope bbox = ReferencedEnvelope(
worldRect,
mapFrame.getMapPane().getMapContent().getCoordinateReferenceSystem());

/*

  • Create a Filter to select features that intersect with

  • the bounding box
    */
    Filter filter = ff.intersects(ff.property(geometryAttributeName), ff.literal(bbox));


/*

  • Use the filter to identify the selected features
    */
    {
    SimpleFeatureCollection selectedFeatures =
    featureSource.getFeatures(filter);


SimpleFeatureIterator iter = selectedFeatures.features();

From ExtractBoundsFilterVisitor

@Override
data) {
;
}

Here’s the stack trace:

Mouse click at: DirectPosition2D[6349881.5871864, 2029348.2224553742]
java.lang.NullPointerException
at org.geotools.data.shapefile.ShapefileFeatureSource.getReaderInternal(ShapefileFeatureSource.java:237)
at org.geotools.data.shapefile.ShapefileFeatureStore.getReaderInternal(ShapefileFeatureStore.java:126)
at org.geotools.data.store.ContentFeatureSource.getReader(ContentFeatureSource.java:563)
at org.geotools.data.store.ContentFeatureCollection.features(ContentFeatureCollection.java:165)
at com.aseg.StyleLab.SelectionLab.selectFeatures(SelectionLab.java:217)
at com.aseg.StyleLab.SelectionLab$1$1.onMouseClicked(SelectionLab.java:161)
at org.geotools.swing.event.DefaultMapMouseEventDispatcher.mouseClicked(DefaultMapMouseEventDispatcher.java:99)
at java.awt.AWTEventMulticaster.mouseClicked(Unknown Source)
at java.awt.AWTEventMulticaster.mouseClicked(Unknown Source)
at java.awt.AWTEventMulticaster.mouseClicked(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)

Environment

None

Activity

Show:
codehaus
April 10, 2015, 3:20 PM

CodeHaus Comment From: rripken - Time: Wed, 25 Mar 2015 14:09:58 -0500
---------------------
The bbox variable is used somewhat inconsistently:

Line 320 its intialized to a new ReferencedEnvelope() - suggesting its not supposed to be null.

Line 335 in ShapefileFeatureStore.getReaderInternal uses bbox in a conditional expression without checking if its null.

Line 384 does a null check on bbox before using the reference.

The base-class (NullFilterVisitor) does return null in some situations.

The base-class (NullFilterVisitor) does do null checks on the result of other accept calls.

I have to conclude that it is "legal" for Visitors to return null.

If that is true then ShapefileFeatureStore line 335 really does need a null check.

codehaus
April 10, 2015, 3:20 PM

CodeHaus Comment From: rripken - Time: Wed, 25 Mar 2015 14:10:59 -0500
---------------------
It seems curious that just about every other method in ExtractBoundsFilterVisitor returns an infinity Envelope or the result of "new Envelope" or "new ReferencedEnvelope()".

Even the base-class implements the visit(PropertyName expression, Object data) method as returning data (just as suggested by @RandallDuart) instead of null.

I'm thinking that maybe this method implementation got auto-generated by some IDE tool?

I also don't see a test for this method in ExtractBoundsFilterVisitorTest.

codehaus
April 10, 2015, 3:20 PM

CodeHaus Comment From: rripken - Time: Wed, 25 Mar 2015 14:12:37 -0500
---------------------
the visit( Intersects filter, Object data ) method doesn't seem right.

Perhaps I don't understand the distinction between an "And" filter and an "Intersect" filter. I would have expected this method:

    public Object visit( Intersects filter, Object data ) {

        data = filter.getExpression1().accept(this, data);

        data = filter.getExpression2().accept(this, data);

        return data;

    }

to do something similar to the "And" implementation:

public Object visit(And filter, Object data) {

Envelope mixed = infinity();

for (Filter f : filter.getChildren()) {

Envelope env = (Envelope) f.accept(this, data);

     mixed = mixed.intersection(env);

}

return mixed;

}

Shannon Newbold
June 7, 2016, 5:24 PM

This issue seems to have been resolved in GeoTools 14.1.

Andrea Aime
February 15, 2017, 11:34 AM

Mass transitioning all resolved issues that have not been updated in the last month to closed state

Assignee

Unassigned

Reporter

codehaus

Triage

None

Components

Fix versions

Affects versions

Priority

Medium
Configure