{"record":{"id":"91613bbc6f1870b8","repo":"OtterMind/Chat2DB","slug":"ewkb-line-string-must-be-empty-or-contain-at-least","errorCode":null,"errorMessage":"EWKB line string must be empty or contain at least two coordinates","messagePattern":"EWKB line string must be empty or contain at least two coordinates","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":233,"sourceCode":"    }\n\n    private void inspectPoint(WkbCursor cursor, ByteOrder byteOrder, int coordinateDimension) {\n        boolean allNaN = true;\n        boolean allFinite = true;\n        for (int i = 0; i < coordinateDimension; i++) {\n            double ordinate = cursor.readDouble(byteOrder);\n            allNaN &= Double.isNaN(ordinate);\n            allFinite &= Double.isFinite(ordinate);\n        }\n        if (!allNaN && !allFinite) {\n            throw new IllegalArgumentException(\"EWKB point contains an invalid empty coordinate\");\n        }\n    }\n\n    private void inspectLineString(WkbCursor cursor, ByteOrder byteOrder, int coordinateDimension) {\n        int coordinateCount = readCount(cursor, byteOrder);\n        if (coordinateCount == 1) {\n            throw new IllegalArgumentException(\"EWKB line string must be empty or contain at least two coordinates\");\n        }\n        inspectFiniteCoordinates(cursor, byteOrder, coordinateCount, coordinateDimension);\n    }\n\n    private void inspectLinearRing(WkbCursor cursor, ByteOrder byteOrder, int coordinateDimension) {\n        int coordinateCount = readCount(cursor, byteOrder);\n        if (coordinateCount < 4) {\n            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        }","sourceCodeStart":215,"sourceCodeEnd":251,"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#L215-L251","documentation":"Thrown by PostgreSQLGeometryProcessor.inspectLineString when parsing EWKB (Extended Well-Known Binary) geometry data. Per the OGC SFA specification, a LINESTRING must declare either zero coordinates (empty geometry) or at least two. A declared count of exactly one is structurally invalid. This validation runs inside convertJDBCValueByType (line 58) while converting a PostgreSQL geometry/geography column from hex-encoded EWKB to WKT for display. The exception is caught at line 80 and the raw hex value is returned, so it degrades gracefully — it surfaces only in debug-level logs.","triggerScenarios":"Converting a PostgreSQL geometry/geography JDBC value whose EWKB binary declares a LINESTRING (baseType 2, dispatched at line 201) with a coordinate count field of exactly 1. Called during convertJDBCValueByType when Chat2DB reads a spatial column for display.","commonSituations":"Corrupt or manually-constructed geometry data; data inserted via binary copy that bypassed PostGIS validation; EWKB produced by an external serialization tool or driver version with different validation strictness.","solutions":["No action required in production — convertJDBCValueByType catches this and returns the raw hex value for display","Repair the source data so LINESTRING columns contain 0 or >=2 coordinates","Run ST_IsValidDetail in PostgreSQL to locate invalid geometries and fix them with ST_MakeValid"],"exampleFix":"-- before: invalid line string with 1 point\nSELECT ST_GeomFromEWKT('LINESTRING(1 2)');\n-- after: valid line string with 2 points\nSELECT ST_GeomFromEWKT('LINESTRING(1 2, 3 4)');","handlingStrategy":"try-catch","validationCode":"// convertJDBCValueByType already catches this at line 80 and returns raw hex.\n// If calling inspectEwkb directly in tests, wrap it:\ntry {\n    processor.convertJDBCValueByType(dataValue);\n} catch (Exception e) {\n    // graceful fallback to raw value\n}","typeGuard":null,"tryCatchPattern":"try {\n    WkbHeader header = inspectEwkb(ewkb);\n    // ... WKT conversion ...\n} catch (Exception e) {\n    log.debug(\"Unable to convert PostgreSQL spatial EWKB for display\", e);\n    return value; // raw hex fallback\n}","preventionTips":["Validate geometry data with ST_IsValid before inserting into PostgreSQL","Use ST_MakeValid to repair invalid geometries at the database level","Ensure LINESTRING columns always contain 0 or >=2 coordinates"],"tags":["postgresql","ewkb","geometry","validation"],"backgroundTag":null,"analyzedSha":"5ee1e990e73fbcae1969dc554be254fedb3ab888","analyzedAt":"2026-08-14T07:05:03.077Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}