TransWikia.com

IndexOutOfBoundsException when using "in" function in GeoServer

Geographic Information Systems Asked on November 21, 2021

I have trouble with the in filter function in SLD submitted to GeoServer. The root cause seems to be within the geotools. Currently we’re using GeoServer Version 2.15.2 and GeoTools Version 21.2. The fact is that with less complex filters the in function seems to work but in this case it does not. We found also an workaround by using or in combination with PropertyIsEqualTo but then the payload is much bigger. I’ve tried also to split the in function into smaller parts so it matches in9 or in10 but then i got similar IndexOutOfBoundsException.

      <ogc:Filter>
        <ogc:And>
          <ogc:Or>
            <PropertyIsEqualTo>
              <ogc:Function name="geometryType">
                <ogc:PropertyName>geom</ogc:PropertyName>
              </ogc:Function>
              <ogc:Literal>Point</ogc:Literal>
            </PropertyIsEqualTo>
            <PropertyIsEqualTo>
              <ogc:Function name="geometryType">
                <ogc:PropertyName>geom</ogc:PropertyName>
              </ogc:Function>
              <ogc:Literal>MultiPoint</ogc:Literal>
            </PropertyIsEqualTo>
          </ogc:Or>
          <ogc:And>
            <ogc:PropertyIsEqualTo>
              <ogc:Function name="in">
                <ogc:Function name="property">
                  <ogc:Literal>feature_type_id</ogc:Literal>
                </ogc:Function>
                <ogc:Literal>7516</ogc:Literal>
                <ogc:Literal>7517</ogc:Literal>
                <ogc:Literal>7518</ogc:Literal>
                <ogc:Literal>7519</ogc:Literal>
                <ogc:Literal>7520</ogc:Literal>
                <ogc:Literal>7521</ogc:Literal>
                <ogc:Literal>7522</ogc:Literal>
                <ogc:Literal>7523</ogc:Literal>
                <ogc:Literal>7524</ogc:Literal>
                <ogc:Literal>7525</ogc:Literal>
                <ogc:Literal>7526</ogc:Literal>
                <ogc:Literal>7527</ogc:Literal>
                <ogc:Literal>7528</ogc:Literal>
                <ogc:Literal>7529</ogc:Literal>
                <ogc:Literal>7530</ogc:Literal>
                <ogc:Literal>7531</ogc:Literal>
                <ogc:Literal>7532</ogc:Literal>
                <ogc:Literal>7533</ogc:Literal>
                <ogc:Literal>7534</ogc:Literal>
                <ogc:Literal>7535</ogc:Literal>
                <ogc:Literal>7536</ogc:Literal>
              </ogc:Function>
              <ogc:Literal>true</ogc:Literal>
            </ogc:PropertyIsEqualTo>
          </ogc:And>
        </ogc:And>
      </ogc:Filter>

The generated SLD may be found here https://gofile.io/d/RWLOUS

Here is a part of the stacktrace:

Caused by: java.lang.IndexOutOfBoundsException: Index 7 out of bounds for length 4
    at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
    at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
    at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:248)
    at java.base/java.util.Objects.checkIndex(Objects.java:372)
    at java.base/java.util.ArrayList.get(ArrayList.java:458)
    at org.geotools.filter.visitor.PostPreProcessFilterSplittingVisitor.visit(PostPreProcessFilterSplittingVisitor.java:873)
    at org.geotools.filter.FunctionExpressionImpl.accept(FunctionExpressionImpl.java:143)
    at org.geotools.filter.visitor.PostPreProcessFilterSplittingVisitor.visitBinaryComparisonOperator(PostPreProcessFilterSplittingVisitor.java:423)
    at org.geotools.filter.visitor.PostPreProcessFilterSplittingVisitor.visit(PostPreProcessFilterSplittingVisitor.java:377)
    at org.geotools.filter.IsEqualsToImpl.accept(IsEqualsToImpl.java:154)
    at org.geotools.filter.visitor.PostPreProcessFilterSplittingVisitor.visitLogicOperator(PostPreProcessFilterSplittingVisitor.java:670)
    at org.geotools.filter.visitor.PostPreProcessFilterSplittingVisitor.visit(PostPreProcessFilterSplittingVisitor.java:599)
    at org.geotools.filter.AndImpl.accept(AndImpl.java:45)
    at org.geotools.filter.visitor.PostPreProcessFilterSplittingVisitor.visitLogicOperator(PostPreProcessFilterSplittingVisitor.java:627)
    at org.geotools.filter.visitor.PostPreProcessFilterSplittingVisitor.visit(PostPreProcessFilterSplittingVisitor.java:604)
    at org.geotools.filter.NotImpl.accept(NotImpl.java:51)
    at org.geotools.filter.visitor.PostPreProcessFilterSplittingVisitor.visitLogicOperator(PostPreProcessFilterSplittingVisitor.java:670)
    at org.geotools.filter.visitor.PostPreProcessFilterSplittingVisitor.visit(PostPreProcessFilterSplittingVisitor.java:599)
    at org.geotools.filter.AndImpl.accept(AndImpl.java:45)
    at org.geotools.filter.visitor.PostPreProcessFilterSplittingVisitor.visitLogicOperator(PostPreProcessFilterSplittingVisitor.java:627)
    at org.geotools.filter.visitor.PostPreProcessFilterSplittingVisitor.visit(PostPreProcessFilterSplittingVisitor.java:604)
    at org.geotools.filter.NotImpl.accept(NotImpl.java:51)
    at org.geotools.filter.visitor.PostPreProcessFilterSplittingVisitor.visitLogicOperator(PostPreProcessFilterSplittingVisitor.java:649)
    at org.geotools.filter.visitor.PostPreProcessFilterSplittingVisitor.visit(PostPreProcessFilterSplittingVisitor.java:609)
    at org.geotools.filter.OrImpl.accept(OrImpl.java:41)
    at org.geotools.filter.visitor.PostPreProcessFilterSplittingVisitor.visitLogicOperator(PostPreProcessFilterSplittingVisitor.java:670)
    at org.geotools.filter.visitor.PostPreProcessFilterSplittingVisitor.visit(PostPreProcessFilterSplittingVisitor.java:599)
    at org.geotools.filter.AndImpl.accept(AndImpl.java:45)

I’ve also tried to create a unit test in PostPreProcessFilterSplittingVisitorTest in geotools which would simulate a part of the xml, but it does not throw any exception

final Not not =
  ff.not(
    ff.and(
      ff.or(
        ff.equal(
          ff.function("geometryType", ff.property("geom")),
            ff.literal("Point"),
            true,
            MultiValuedFilter.MatchAction.ANY
        ),
        ff.equal(
          ff.function("geometryType", ff.property("geom")),
          ff.literal("MultiPoint"),
          true,
          MultiValuedFilter.MatchAction.ANY
        )
      ),
      ff.equal(
        ff.function(
          "in", 
          ff.function("property", ff.literal("feature_type_id")),
          ff.literal(7516),
          ff.literal(7517),
          ff.literal(7518),
          ff.literal(7519),
          ff.literal(7520),
          ff.literal(7521),
          ff.literal(7522),
          ff.literal(7523),
          ff.literal(7524),
          ff.literal(7525),
          ff.literal(7526),
          ff.literal(7527),
          ff.literal(7528),
          ff.literal(7529),
          ff.literal(7530),
          ff.literal(7531),
          ff.literal(7532),
          ff.literal(7533),
          ff.literal(7534),
          ff.literal(7535),
          ff.literal(7536)
        ),
        ff.literal(true),
        true,
        MultiValuedFilter.MatchAction.ANY
      )
    )
  );
  final And andFilter = ff.and(Collections.singletonList(not));
  final PostPreProcessFilterSplittingVisitor postprocessFilter =
                newVisitor(new FilterCapabilities());
        
  andFilter.accept(postprocessFilter, null);

One Answer

There was a recent fix in GeoTools which fixes this issue https://osgeo-org.atlassian.net/browse/GEOT-6746

Answered by milan on November 21, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP