{"record":{"id":"1b1e23b28e1c1357","repo":"elastic/elasticsearch","slug":"input-is-a-base-cell","errorCode":null,"errorMessage":"Input is a base cell","messagePattern":"Input is a base cell","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"libs/h3/src/main/java/org/elasticsearch/h3/H3.java","lineNumber":225,"sourceCode":"     * Find the H3 index of the resolution <code>res</code> cell containing the lat/lon (in degrees)\n     *\n     * @param lat Latitude in degrees.\n     * @param lng Longitude in degrees.\n     * @param res Resolution, 0 &lt;= res &lt;= 15\n     * @return The H3 index.\n     * @throws IllegalArgumentException Latitude, longitude, or resolution is out of range.\n     */\n    public static String geoToH3Address(double lat, double lng, int res) {\n        return h3ToString(geoToH3(lat, lng, res));\n    }\n\n    /**\n     * Returns the parent of the given index.\n     */\n    public static long h3ToParent(long h3) {\n        int childRes = H3Index.H3_get_resolution(h3);\n        if (childRes == 0) {\n            throw new IllegalArgumentException(\"Input is a base cell\");\n        }\n        long parentH = H3Index.H3_set_resolution(h3, childRes - 1);\n        return H3Index.H3_set_index_digit(parentH, childRes, H3Index.H3_DIGIT_MASK);\n    }\n\n    /**\n     * Returns the parent of the given index.\n     */\n    public static String h3ToParent(String h3Address) {\n        long parent = h3ToParent(stringToH3(h3Address));\n        return h3ToString(parent);\n    }\n\n    /**\n     * Returns the children of the given index.\n     */\n    public static long[] h3ToChildren(long h3) {\n        final long[] children = new long[h3ToChildrenSize(h3)];","sourceCodeStart":207,"sourceCodeEnd":243,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/libs/h3/src/main/java/org/elasticsearch/h3/H3.java#L207-L243","documentation":"Thrown by H3.h3ToParent when the input index is already at resolution 0. Resolution-0 cells are the 122 base cells and have no parent; requesting one is meaningless, so the method refuses rather than producing a nonsensical result. The string overload re-throws the same exception after converting via stringToH3.","triggerScenarios":"Calling H3.h3ToParent(h3) or H3.h3ToParent(address) on a res-0 index (e.g. one returned by getLongRes0Cells, or geoToH3(lat,lng,0)). Also when iterating parents in a loop that does not stop before reaching res 0.","commonSituations":"Writing a loop that walks up the hierarchy (h3ToParent repeatedly) without a base case; consuming an index whose resolution you did not check; mixing res-0 cells from a polar/overview dataset into a parent-walk routine.","solutions":["Check H3.getResolution(h3) > 0 before calling h3ToParent, and stop the walk at res 0.","If you need a coarse ancestor, query h3ToParent only for resolutions > 0 and treat res 0 as the root.","Validate user-supplied indexes with getResolution and reject/clamp res-0 input upstream."],"exampleFix":"// before\nlong parent = H3.h3ToParent(cell); // throws if cell is res 0\n\n// after\nlong parent = H3.getResolution(cell) > 0 ? H3.h3ToParent(cell) : cell;","handlingStrategy":"validation","validationCode":"static long safeParent(long h3) {\n    if (org.elasticsearch.h3.H3.getResolution(h3) == 0) {\n        throw new IllegalArgumentException(\"res-0 cell has no parent: \" + h3);\n    }\n    return org.elasticsearch.h3.H3.h3ToParent(h3);\n}","typeGuard":"static boolean hasParent(long h3) {\n    return org.elasticsearch.h3.H3.getResolution(h3) > 0;\n}","tryCatchPattern":"try {\n    return H3.h3ToParent(h3);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().equals(\"Input is a base cell\")) return h3; // already root\n    throw e;\n}","preventionTips":["Always check getResolution > 0 before walking up.","Stop parent-walk loops at res 0.","Track each index's resolution alongside the long if you walk hierarchies often."],"tags":["h3","parent","resolution","validation"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}