{"record":{"id":"9c823d29e028e5df","repo":"elastic/elasticsearch","slug":"all-elements-of-the-collection-should-have-the-sam-9c823d","errorCode":null,"errorMessage":"all elements of the collection should have the same number of dimension","messagePattern":"all elements of the collection should have the same number of dimension","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"libs/geo/src/main/java/org/elasticsearch/geometry/utils/WellKnownBinary.java","lineNumber":405,"sourceCode":"        ByteArrayOutputStream out,\n        ByteBuffer scratch,\n        boolean explicitZ,\n        GeometryValidator validator\n    ) throws IOException, ParseException {\n        if (WellKnownText.nextEmptyOrOpen(stream).equals(WellKnownText.EMPTY)) {\n            writeInt(out, scratch, 5);\n            writeInt(out, scratch, 0);\n            return;\n        }\n        List<CoordsList> lines = new ArrayList<>();\n        CoordsList firstLine = wktReadLineStringCoords(stream, validator);\n        lines.add(firstLine);\n        boolean hasZ = firstLine.hasZ();\n        while (WellKnownText.nextCloserOrComma(stream).equals(WellKnownText.COMMA)) {\n            CoordsList line = wktReadLineStringCoords(stream, validator);\n            lines.add(line);\n            if (line.hasZ() != hasZ) {\n                throw new IllegalArgumentException(\"all elements of the collection should have the same number of dimension\");\n            }\n        }\n        WellKnownText.checkZorMAttribute(explicitZ, hasZ);\n        writeInt(out, scratch, hasZ ? 1005 : 5);\n        writeInt(out, scratch, lines.size());\n        byte byteOrderByte = (byte) (scratch.order() == ByteOrder.BIG_ENDIAN ? 0 : 1);\n        for (CoordsList line : lines) {\n            out.write(byteOrderByte);\n            writeInt(out, scratch, hasZ ? 1002 : 2);\n            writeInt(out, scratch, line.size());\n            writeCoordinateList(out, scratch, line);\n        }\n    }\n\n    private static void writeWKBMultiPolygon(\n        StreamTokenizer stream,\n        ByteArrayOutputStream out,\n        ByteBuffer scratch,","sourceCodeStart":387,"sourceCodeEnd":423,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/libs/geo/src/main/java/org/elasticsearch/geometry/utils/WellKnownBinary.java#L387-L423","documentation":"writeWKBMultiLineString (line 385) reads the first linestring's coordinates, records hasZ from it (line 400), then reads each subsequent linestring and at line 404 throws IllegalArgumentException if its hasZ differs from the first. WKB MULTILINESTRING (type 5 or 1005) is uniformly 2D or uniformly 3D per geometry; mixed-dimension components are not representable.","triggerScenarios":"Calling WellKnownBinary.fromWKT with a MULTILINESTRING WKT where some linestrings have Z and others do not, e.g. 'MULTILINESTRING((0 0, 1 1), (2 2 2, 3 3 3))'. Triggered during direct WKT-to-WKB conversion only.","commonSituations":"Combining linestring data from heterogeneous sources (some GPS tracks with elevation, some without). Authoring tools that conditionally emit Z. ETL pipelines that union linestrings without dimension normalization.","solutions":["Normalize dimensionality across all linestrings in the MULTILINESTRING: drop Z from all or add Z (e.g. 0) to all.","Split a mixed-dimension MULTILINESTRING into separate homogeneous geometries.","Validate per-component hasZ before fromWKT and reject or normalize upstream."],"exampleFix":"// before — mixed\nfromWKT(\"MULTILINESTRING((0 0, 1 1), (2 2 2, 3 3 3))\", BO, false, v);\n// throws: all elements of the collection should have the same number of dimension\n\n// after — all 2D\nfromWKT(\"MULTILINESTRING((0 0, 1 1), (2 2, 3 3))\", BO, false, v);","handlingStrategy":"validation","validationCode":"boolean componentsUniformZ(List<boolean> compHasZ) {\n    Boolean first = null;\n    for (boolean z : compHasZ) {\n        if (first == null) first = z;\n        else if (z != first) return false;\n    }\n    return true;\n}","typeGuard":"static boolean multiLineUniformZ(MultiLine ml) {\n    boolean first = ml.isEmpty() ? false : ml.get(0).hasZ();\n    for (Line l : ml) if (l.hasZ() != first) return false;\n    return true;\n}","tryCatchPattern":"try {\n    return WellKnownBinary.fromWKT(wkt, bo, coerce, v);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"same number of dimension\")) {\n        // normalize Z across linestrings, then retry\n    } else throw e;\n}","preventionTips":["Normalize Z across all linestrings in a MULTILINESTRING before fromWKT.","Split mixed-dimension multi-geometries into homogeneous ones at ingest.","Add a uniform-dimension validator to your ETL pre-checks."],"tags":["geo","wkt","wkb","multilinestring","z-value","dimensionality","elasticsearch"],"backgroundTag":null,"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}