OtterMind/Chat2DB · info · IllegalArgumentException
EWKB line string must be empty or contain at least two coord
Error message
EWKB line string must be empty or contain at least two coordinates
What it means
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.
Source
Thrown at chat2db-community-server/chat2db-community-plugins/chat2db-community-postgresql/src/main/java/ai/chat2db/plugin/postgresql/value/sub/PostgreSQLGeometryProcessor.java:233
}
private void inspectPoint(WkbCursor cursor, ByteOrder byteOrder, int coordinateDimension) {
boolean allNaN = true;
boolean allFinite = true;
for (int i = 0; i < coordinateDimension; i++) {
double ordinate = cursor.readDouble(byteOrder);
allNaN &= Double.isNaN(ordinate);
allFinite &= Double.isFinite(ordinate);
}
if (!allNaN && !allFinite) {
throw new IllegalArgumentException("EWKB point contains an invalid empty coordinate");
}
}
private void inspectLineString(WkbCursor cursor, ByteOrder byteOrder, int coordinateDimension) {
int coordinateCount = readCount(cursor, byteOrder);
if (coordinateCount == 1) {
throw new IllegalArgumentException("EWKB line string must be empty or contain at least two coordinates");
}
inspectFiniteCoordinates(cursor, byteOrder, coordinateCount, coordinateDimension);
}
private void inspectLinearRing(WkbCursor cursor, ByteOrder byteOrder, int coordinateDimension) {
int coordinateCount = readCount(cursor, byteOrder);
if (coordinateCount < 4) {
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");
}
}View on GitHub (pinned to 5ee1e990e7)
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
Example fix
-- before: invalid line string with 1 point
SELECT ST_GeomFromEWKT('LINESTRING(1 2)');
-- after: valid line string with 2 points
SELECT ST_GeomFromEWKT('LINESTRING(1 2, 3 4)'); Defensive patterns
Strategy: try-catch
Validate before calling
// convertJDBCValueByType already catches this at line 80 and returns raw hex.
// If calling inspectEwkb directly in tests, wrap it:
try {
processor.convertJDBCValueByType(dataValue);
} catch (Exception e) {
// graceful fallback to raw value
} Try / catch
try {
WkbHeader header = inspectEwkb(ewkb);
// ... WKT conversion ...
} catch (Exception e) {
log.debug("Unable to convert PostgreSQL spatial EWKB for display", e);
return value; // raw hex fallback
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- EWKB linear ring must contain at least four coordinates
- EWKB linear ring is not closed
- EWKB coordinate is not finite
- EWKB collection contains an unexpected geometry type
- EWKB collection contains mixed coordinate dimensions
AI-assisted analysis of OtterMind/Chat2DB@5ee1e990e7 (2026-08-14).
Data as JSON: /api/errors/91613bbc6f1870b8.
Report an issue: GitHub.