OtterMind/Chat2DB · info · IllegalArgumentException

EWKB coordinate is not finite

Error message

EWKB coordinate is not finite

What it means

Thrown by PostgreSQLGeometryProcessor.inspectFiniteCoordinates when any ordinate value read from the EWKB byte stream is not finite (NaN or Infinity, per Double.isFinite). This method iterates all coordinate/ordinate pairs in a LINESTRING or the interior coordinates of a polygon ring (count - 2, excluding first and last which are checked separately via readFiniteCoordinate). The exception is caught by convertJDBCValueByType at line 80 and the raw hex value is returned gracefully.

Source

Thrown at chat2db-community-server/chat2db-community-plugins/chat2db-community-postgresql/src/main/java/ai/chat2db/plugin/postgresql/value/sub/PostgreSQLGeometryProcessor.java:259

            throw new IllegalArgumentException("EWKB linear ring must contain at least four coordinates");
        }

        double[] firstCoordinate = readFiniteCoordinate(cursor, byteOrder, coordinateDimension);
        inspectFiniteCoordinates(cursor, byteOrder, coordinateCount - 2, coordinateDimension);
        double[] lastCoordinate = readFiniteCoordinate(cursor, byteOrder, coordinateDimension);
        for (int i = 0; i < 2; i++) {
            if (firstCoordinate[i] != lastCoordinate[i]) {
                throw new IllegalArgumentException("EWKB linear ring is not closed");
            }
        }
    }

    private void inspectFiniteCoordinates(WkbCursor cursor, ByteOrder byteOrder,
                                          int coordinateCount, int coordinateDimension) {
        for (int coordinate = 0; coordinate < coordinateCount; coordinate++) {
            for (int ordinate = 0; ordinate < coordinateDimension; ordinate++) {
                if (!Double.isFinite(cursor.readDouble(byteOrder))) {
                    throw new IllegalArgumentException("EWKB coordinate is not finite");
                }
            }
        }
    }

    private double[] readFiniteCoordinate(WkbCursor cursor, ByteOrder byteOrder, int coordinateDimension) {
        double[] coordinate = new double[coordinateDimension];
        for (int i = 0; i < coordinateDimension; i++) {
            coordinate[i] = cursor.readDouble(byteOrder);
            if (!Double.isFinite(coordinate[i])) {
                throw new IllegalArgumentException("EWKB coordinate is not finite");
            }
        }
        return coordinate;
    }

    private void inspectChildren(WkbCursor cursor, ByteOrder byteOrder, WkbHeader parent,
                                 Integer inheritedSrid, int expectedType, int depth) {

View on GitHub (pinned to 5ee1e990e7)

Solutions

  1. No action required in production — convertJDBCValueByType catches this and returns the raw hex value
  2. Inspect the source data with a hex dump to locate the corrupt coordinate bytes
  3. Replace invalid coordinates with valid finite values or re-import the geometry from a trusted source

Example fix

// before: EWKB contains a coordinate whose double bits are NaN/Infinity
// after: ensure all coordinate doubles pass Double.isFinite before serialization
Defensive patterns

Strategy: try-catch

Validate before calling

// Already caught in convertJDBCValueByType. For data-level validation:
// Check for non-finite coordinates in EWKB binary before parsing:
byte[] ewkb = WKBReader.hexToBytes(hexValue);
// JTS WKBReader may tolerate NaN; the Chat2DB guard is stricter.

Try / catch

try {
    inspectFiniteCoordinates(cursor, byteOrder, count, dim);
} catch (IllegalArgumentException e) {
    log.debug("EWKB coordinate not finite", e);
    return value;
}

Prevention

When it happens

Trigger: Converting EWKB data where any coordinate's IEEE 754 double value is NaN or +/- Infinity. Called from inspectLineString (line 235) for the coordinate body, and from inspectLinearRing (line 245) for interior ring coordinates.

Common situations: Corrupt binary data where byte patterns decode to NaN or Infinity; coordinates produced by a division-by-zero or overflow in the source system; bit-flipped or truncated binary from storage corruption.

Related errors


AI-assisted analysis of OtterMind/Chat2DB@5ee1e990e7 (2026-08-14). Data as JSON: /api/errors/0eb0a631b30f04e9. Report an issue: GitHub.