We're updating the issue view to help you get more done. 

BBox function crashes when passed GML

Description

When transforming a SLD with a BBox filter to XML an exception occurs:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 ERROR: 'Cannot encode org.locationtech.jts.geom.Envelope should be Filter or Expression' javax.xml.transform.TransformerException: java.lang.IllegalArgumentException: Cannot encode org.locationtech.jts.geom.Envelope should be Filter or Expression at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:737) at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:343) at org.geotools.xml.transform.TransformerBase$Task.run(TransformerBase.java:283) at org.geotools.xml.transform.TransformerBase.transform(TransformerBase.java:118) at org.geotools.xml.transform.TransformerBase.transform(TransformerBase.java:108) at org.geotools.xml.transform.TransformerBase.transform(TransformerBase.java:145) at com.sldeditor.test.App.main(App.java:42) Caused by: java.lang.IllegalArgumentException: Cannot encode org.locationtech.jts.geom.Envelope should be Filter or Expression at org.geotools.xml.filter.FilterTransformer$FilterTranslator.encode(FilterTransformer.java:489) at org.geotools.xml.filter.FilterTransformer$FilterTranslator.visit(FilterTransformer.java:330) at org.geotools.filter.spatial.BBOXImpl.accept(BBOXImpl.java:216) at org.geotools.xml.filter.FilterTransformer$FilterTranslator.encode(FilterTransformer.java:482) at org.geotools.xml.styling.SLDTransformer$SLDTranslator.visit(SLDTransformer.java:1174) at org.geotools.xml.styling.SLDTransformer$SLDTranslator.visit(SLDTransformer.java:874) at org.geotools.styling.RuleImpl.accept(RuleImpl.java:303) at org.geotools.xml.styling.SLDTransformer$SLDTranslator.visit(SLDTransformer.java:1238) at org.geotools.xml.styling.SLDTransformer$SLDTranslator.visit(SLDTransformer.java:1199) at org.geotools.xml.styling.SLDTransformer$SLDTranslator.visit(SLDTransformer.java:1019) at org.geotools.xml.styling.SLDTransformer$SLDTranslator.visit(SLDTransformer.java:991) at org.geotools.styling.StyledLayerDescriptorImpl.accept(StyledLayerDescriptorImpl.java:170) at org.geotools.xml.styling.SLDTransformer$SLDTranslator.encode(SLDTransformer.java:1375) at org.geotools.xml.styling.SLDTransformer$SLDTranslator.encode(SLDTransformer.java:1384) at org.geotools.xml.transform.TransformerBase$XMLReaderSupport.parse(TransformerBase.java:995) at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transformIdentity(TransformerImpl.java:659) at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:728) ... 6 more

The issue can be demonstrated by unzipping the attached bbox-issue and typing:

1 2 mvn clean install java -jar bbox-issue.jar point_bbox.sld

The issue is caused in org.geotools.filter.FilterTransformer

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 public Object visit(BBOX filter, Object extraData) { Expression left = filter.getExpression1(); Expression right = filter.getExpression2(); final String type = "BBOX"; start(type); left.accept(this, extraData); if (right instanceof Literal) { Literal literal = (Literal) right; Envelope bbox = literal.evaluate(null, Envelope.class); if (bbox != null) { encode(bbox); } else { right.accept(this, extraData); } } else { right.accept(this, extraData); } end(type); return extraData; }

The

1 encode()

method called in the middle of the method above only expects an object of type Filter or Expression hence the exception.

Environment

Windows 7 Java 8

Status

Assignee

Unassigned

Reporter

Robert Ward

Triage

Components

Fix versions

Affects versions

20.0
21.0
20.1

Priority

Highest