{"record":{"id":"fcb33e2fa23c5ed6","repo":"OtterMind/Chat2DB","slug":"ewkb-collection-contains-an-unexpected-geometry-ty","errorCode":null,"errorMessage":"EWKB collection contains an unexpected geometry type","messagePattern":"EWKB collection contains an unexpected geometry type","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":283,"sourceCode":"    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) {\n        int childCount = readCount(cursor, byteOrder);\n        Integer effectiveSrid = parent.srid() != null ? parent.srid() : inheritedSrid;\n        for (int i = 0; i < childCount; i++) {\n            WkbHeader child = inspectGeometry(cursor, effectiveSrid, false, depth + 1);\n            if (expectedType != 0 && child.baseType() != expectedType) {\n                throw new IllegalArgumentException(\"EWKB collection contains an unexpected geometry type\");\n            }\n            if (child.hasZ() != parent.hasZ() || child.hasMeasure() != parent.hasMeasure()) {\n                throw new IllegalArgumentException(\"EWKB collection contains mixed coordinate dimensions\");\n            }\n        }\n    }\n\n    private int readCount(WkbCursor cursor, ByteOrder byteOrder) {\n        int count = cursor.readInt(byteOrder);\n        if (count < 0) {\n            throw new IllegalArgumentException(\"EWKB contains a negative element count\");\n        }\n        return count;\n    }\n\n    private ByteOrder readByteOrder(WkbCursor cursor) {\n        int byteOrder = cursor.readUnsignedByte();\n        if (byteOrder == 0) {","sourceCodeStart":265,"sourceCodeEnd":301,"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#L265-L301","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"-- before: MULTIPOINT containing a LINESTRING child (invalid)\n-- after: MULTIPOINT containing only POINT children\nSELECT ST_GeomFromEWKT('MULTIPOINT(0 0, 1 1)');","handlingStrategy":"try-catch","validationCode":"// Already caught in convertJDBCValueByType. For data-level validation:\n// Ensure MULTIPOINT contains only POINTs, MULTILINESTRING only LINESTRINGs, etc.\n// Use ST_IsValid to verify collection homogeneity.","typeGuard":null,"tryCatchPattern":"try {\n    inspectChildren(cursor, byteOrder, header, srid, expectedType, depth);\n} catch (IllegalArgumentException e) {\n    log.debug(\"EWKB collection type mismatch\", e);\n    return value;\n}","preventionTips":["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"],"tags":["postgresql","ewkb","geometry","collection","validation"],"backgroundTag":null,"analyzedSha":"5ee1e990e73fbcae1969dc554be254fedb3ab888","analyzedAt":"2026-08-14T07:05:03.077Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}