Skip to content

ST_IsPolygonCW and ST_IsPolygonCCW mishandle empty polygonal geometries #3171

Closed

Description

@jiayuasu

Expected behavior

ST_IsPolygonCW and ST_IsPolygonCCW should handle empty polygonal geometries without throwing. Both predicates should return true when the input has no rings to violate the requested orientation, consistent with the documented PostGIS semantics:

Actual behavior

  • POLYGON EMPTY returns true from ST_IsPolygonCW but false from ST_IsPolygonCCW.
  • MULTIPOLYGON EMPTY throws ArrayIndexOutOfBoundsException from both predicates.

The common implementations unconditionally call getGeometryN(0) for every MultiPolygon, including an empty one.

Steps to reproduce the problem

SELECT
    ST_IsPolygonCW(ST_GeomFromWKT('POLYGON EMPTY')),
    ST_IsPolygonCCW(ST_GeomFromWKT('POLYGON EMPTY'));

SELECT
    ST_IsPolygonCW(ST_GeomFromWKT('MULTIPOLYGON EMPTY')),
    ST_IsPolygonCCW(ST_GeomFromWKT('MULTIPOLYGON EMPTY'));

The first query returns (true, false). The second query fails with an error whose cause is:

java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
    at org.locationtech.jts.geom.GeometryCollection.getGeometryN(...)
    at org.apache.sedona.common.Functions.isPolygonCW(...)

The same unconditional first-element access exists in isPolygonCCW.

Settings

Sedona version = 1.9.1-SNAPSHOT

Apache Spark version = 3.4

Apache Flink version = The affected implementation is shared by all engines

API type = Spark SQL / common Java functions

Scala version = 2.12

JRE version = 17

Python version = 3.12

Environment = Standalone

Activity

  1. added 2 commits that reference this issue on Jul 26, 2026
  2. added a commit that references this issue on Jul 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions