{"record":{"id":"0eb0a631b30f04e9","repo":"OtterMind/Chat2DB","slug":"ewkb-coordinate-is-not-finite","errorCode":null,"errorMessage":"EWKB coordinate is not finite","messagePattern":"EWKB coordinate is not finite","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"info","filePath":"chat2db-community-server/chat2db-community-plugins/chat2db-community-postgresql/src/main/java/ai/chat2db/plugin/postgresql/value/sub/PostgreSQLGeometryProcessor.java","lineNumber":259,"sourceCode":"            throw new IllegalArgumentException(\"EWKB linear ring must contain at least four coordinates\");\n        }\n\n        double[] firstCoordinate = readFiniteCoordinate(cursor, byteOrder, coordinateDimension);\n        inspectFiniteCoordinates(cursor, byteOrder, coordinateCount - 2, coordinateDimension);\n        double[] lastCoordinate = readFiniteCoordinate(cursor, byteOrder, coordinateDimension);\n        for (int i = 0; i < 2; i++) {\n            if (firstCoordinate[i] != lastCoordinate[i]) {\n                throw new IllegalArgumentException(\"EWKB linear ring is not closed\");\n            }\n        }\n    }\n\n    private void inspectFiniteCoordinates(WkbCursor cursor, ByteOrder byteOrder,\n                                          int coordinateCount, int coordinateDimension) {\n        for (int coordinate = 0; coordinate < coordinateCount; coordinate++) {\n            for (int ordinate = 0; ordinate < coordinateDimension; ordinate++) {\n                if (!Double.isFinite(cursor.readDouble(byteOrder))) {\n                    throw new IllegalArgumentException(\"EWKB coordinate is not finite\");\n                }\n            }\n        }\n    }\n\n    private double[] readFiniteCoordinate(WkbCursor cursor, ByteOrder byteOrder, int coordinateDimension) {\n        double[] coordinate = new double[coordinateDimension];\n        for (int i = 0; i < coordinateDimension; i++) {\n            coordinate[i] = cursor.readDouble(byteOrder);\n            if (!Double.isFinite(coordinate[i])) {\n                throw new IllegalArgumentException(\"EWKB coordinate is not finite\");\n            }\n        }\n        return coordinate;\n    }\n\n    private void inspectChildren(WkbCursor cursor, ByteOrder byteOrder, WkbHeader parent,\n                                 Integer inheritedSrid, int expectedType, int depth) {","sourceCodeStart":241,"sourceCodeEnd":277,"githubUrl":"https://github.com/OtterMind/Chat2DB/blob/5ee1e990e73fbcae1969dc554be254fedb3ab888/chat2db-community-server/chat2db-community-plugins/chat2db-community-postgresql/src/main/java/ai/chat2db/plugin/postgresql/value/sub/PostgreSQLGeometryProcessor.java#L241-L277","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["No action required in production — convertJDBCValueByType catches this and returns the raw hex value","Inspect the source data with a hex dump to locate the corrupt coordinate bytes","Replace invalid coordinates with valid finite values or re-import the geometry from a trusted source"],"exampleFix":"// before: EWKB contains a coordinate whose double bits are NaN/Infinity\n// after: ensure all coordinate doubles pass Double.isFinite before serialization","handlingStrategy":"try-catch","validationCode":"// Already caught in convertJDBCValueByType. For data-level validation:\n// Check for non-finite coordinates in EWKB binary before parsing:\nbyte[] ewkb = WKBReader.hexToBytes(hexValue);\n// JTS WKBReader may tolerate NaN; the Chat2DB guard is stricter.","typeGuard":null,"tryCatchPattern":"try {\n    inspectFiniteCoordinates(cursor, byteOrder, count, dim);\n} catch (IllegalArgumentException e) {\n    log.debug(\"EWKB coordinate not finite\", e);\n    return value;\n}","preventionTips":["Validate that all coordinate doubles are finite before serializing to EWKB","Check for NaN/Infinity in source data before geometry construction","Use ST_IsValid to catch geometries with problematic coordinates"],"tags":["postgresql","ewkb","geometry","data-integrity","validation"],"backgroundTag":null,"analyzedSha":"5ee1e990e73fbcae1969dc554be254fedb3ab888","analyzedAt":"2026-08-14T07:05:03.077Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}