OtterMind/Chat2DB · info · IllegalArgumentException
EWKB collection contains an unexpected geometry type
Error message
EWKB collection contains an unexpected geometry type
What it means
Thrown by PostgreSQLGeometryProcessor.inspectChildren when a child geometry in a collection does not match the expected base type. OGC SFA requires homogeneous collections: MULTIPOINT (baseType 4, expectedType 1) must contain only POINTs, MULTILINESTRING (baseType 5, expectedType 2) only LINESTRINGs, MULTIPOLYGON (baseType 6, expectedType 3) only POLYGONs. GEOMETRYCOLLECTION (baseType 7, expectedType 0) skips this check. 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:283
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) {
int childCount = readCount(cursor, byteOrder);
Integer effectiveSrid = parent.srid() != null ? parent.srid() : inheritedSrid;
for (int i = 0; i < childCount; i++) {
WkbHeader child = inspectGeometry(cursor, effectiveSrid, false, depth + 1);
if (expectedType != 0 && child.baseType() != expectedType) {
throw new IllegalArgumentException("EWKB collection contains an unexpected geometry type");
}
if (child.hasZ() != parent.hasZ() || child.hasMeasure() != parent.hasMeasure()) {
throw new IllegalArgumentException("EWKB collection contains mixed coordinate dimensions");
}
}
}
private int readCount(WkbCursor cursor, ByteOrder byteOrder) {
int count = cursor.readInt(byteOrder);
if (count < 0) {
throw new IllegalArgumentException("EWKB contains a negative element count");
}
return count;
}
private ByteOrder readByteOrder(WkbCursor cursor) {
int byteOrder = cursor.readUnsignedByte();
if (byteOrder == 0) {View on GitHub (pinned to 5ee1e990e7)
Solutions
- No action required in production — convertJDBCValueByType catches this and returns the raw hex value
- Rebuild the collection so all children match the parent's expected type
- Use a GEOMETRYCOLLECTION if heterogeneous child types are genuinely needed
Example fix
-- before: MULTIPOINT containing a LINESTRING child (invalid)
-- after: MULTIPOINT containing only POINT children
SELECT ST_GeomFromEWKT('MULTIPOINT(0 0, 1 1)'); Defensive patterns
Strategy: try-catch
Validate before calling
// Already caught in convertJDBCValueByType. For data-level validation: // Ensure MULTIPOINT contains only POINTs, MULTILINESTRING only LINESTRINGs, etc. // Use ST_IsValid to verify collection homogeneity.
Try / catch
try {
inspectChildren(cursor, byteOrder, header, srid, expectedType, depth);
} catch (IllegalArgumentException e) {
log.debug("EWKB collection type mismatch", e);
return value;
} Prevention
- Ensure all children in a MULTI* collection match the expected base type
- Use GEOMETRYCOLLECTION for genuinely heterogeneous collections
- Validate collection structure at construction time with ST_IsValid
When it happens
Trigger: Converting a MULTIPOINT, MULTILINESTRING, or MULTIPOLYGON whose EWKB children have a base type that differs from the collection's expected type. The check at line 282 compares child.baseType() to expectedType when expectedType is non-zero.
Common situations: Malformed collection geometry where a wrong child type was inserted; data produced by a library that does not enforce collection homogeneity; manually constructed EWKB with mismatched child types.
Related errors
- EWKB collection contains mixed coordinate dimensions
- EWKB line string must be empty or contain at least two coord
- EWKB linear ring must contain at least four coordinates
- EWKB linear ring is not closed
- EWKB coordinate is not finite
AI-assisted analysis of OtterMind/Chat2DB@5ee1e990e7 (2026-08-14).
Data as JSON: /api/errors/fcb33e2fa23c5ed6.
Report an issue: GitHub.