{"record":{"id":"347b6d646c31b179","repo":"elastic/elasticsearch","slug":"unknown-simplification-error-calculator","errorCode":null,"errorMessage":"Unknown simplification error calculator: ","messagePattern":"Unknown simplification error calculator: ","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"libs/geo/src/main/java/org/elasticsearch/geometry/simplify/SimplificationErrorCalculator.java","lineNumber":41,"sourceCode":"        double x();\n\n        double y();\n    }\n\n    SimplificationErrorCalculator CARTESIAN_TRIANGLE_AREA = new CartesianTriangleAreaCalculator();\n    SimplificationErrorCalculator TRIANGLE_AREA = new TriangleAreaCalculator();\n    SimplificationErrorCalculator TRIANGLE_HEIGHT = new TriangleHeightCalculator();\n    SimplificationErrorCalculator HEIGHT_AND_BACKPATH_DISTANCE = new CartesianHeightAndBackpathDistanceCalculator();\n    SimplificationErrorCalculator SPHERICAL_HEIGHT_AND_BACKPATH_DISTANCE = new SphericalHeightAndBackpathDistanceCalculator();\n\n    static SimplificationErrorCalculator byName(String calculatorName) {\n        return switch (calculatorName.toLowerCase(Locale.ROOT)) {\n            case \"cartesiantrianglearea\" -> CARTESIAN_TRIANGLE_AREA;\n            case \"trianglearea\" -> TRIANGLE_AREA;\n            case \"triangleheight\" -> TRIANGLE_HEIGHT;\n            case \"heightandbackpathdistance\" -> HEIGHT_AND_BACKPATH_DISTANCE;\n            case \"sphericalheightandbackpathdistance\" -> SPHERICAL_HEIGHT_AND_BACKPATH_DISTANCE;\n            default -> throw new IllegalArgumentException(\"Unknown simplification error calculator: \" + calculatorName);\n        };\n    }\n\n    /**\n     * Calculate the triangle area using cartesian coordinates as described at\n     * <a href=\"https://en.wikipedia.org/wiki/Area_of_a_triangle\">Area of a triangle</a>\n     */\n    class CartesianTriangleAreaCalculator implements SimplificationErrorCalculator {\n\n        @Override\n        public double calculateError(PointLike left, PointLike middle, PointLike right) {\n            double xb = middle.x() - left.x();\n            double yb = middle.y() - left.y();\n            double xc = right.x() - left.x();\n            double yc = right.y() - left.y();\n            return 0.5 * Math.abs(xb * yc - xc * yb);\n        }\n    }","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/libs/geo/src/main/java/org/elasticsearch/geometry/simplify/SimplificationErrorCalculator.java#L23-L59","documentation":"Thrown by SimplificationErrorCalculator.byName(String) when the supplied name (case-insensitively matched) is not one of the five registered calculators. The method uses a switch expression with a default branch that rejects any unrecognized name; this is a configuration-resolution error, not a geometry error.","triggerScenarios":"Calling `SimplificationErrorCalculator.byName(name)` with a string other than: \"cartesiantrianglearea\", \"trianglearea\", \"triangleheight\", \"heightandbackpathdistance\", or \"sphericalheightandbackpathdistance\". Matching is done after toLowerCase(Locale.ROOT) so case does not matter, but spelling and the 'cartesian'/'spherical' prefix do.","commonSituations":"Passing a user-supplied or config-file value into the calculator selector without validating it; typos like \"triangleArea\" vs the expected \"trianglearea\" (case-insensitive but exact spelling); version drift where a calculator name was renamed or removed between releases; copy-pasting a display label instead of the internal key.","solutions":["Use one of the exact keys: cartesiantrianglearea, trianglearea, triangleheight, heightandbackpathdistance, sphericalheightandbackpathdistance.","Validate the user-supplied name against the known set before calling byName, and surface a clear configuration error to the operator.","Reference the constants on SimplificationErrorCalculator (CARTESIAN_TRIANGLE_AREA, TRIANGLE_AREA, etc.) directly when wiring code, instead of round-tripping through string names."],"exampleFix":"// before\nvar calc = SimplificationErrorCalculator.byName(\"triangle-area\"); // hyphen not allowed\n\n// after\nvar calc = SimplificationErrorCalculator.byName(\"trianglearea\");\n// or skip the string layer entirely\nvar calc = SimplificationErrorCalculator.TRIANGLE_AREA;","handlingStrategy":"validation","validationCode":"Set<String> valid = Set.of(\"cartesiantrianglearea\", \"trianglearea\", \"triangleheight\",\n    \"heightandbackpathdistance\", \"sphericalheightandbackpathdistance\");\nString key = name.toLowerCase(Locale.ROOT);\nif (!valid.contains(key)) throw new IllegalArgumentException(\"Unknown calculator: \" + name);\nreturn SimplificationErrorCalculator.byName(name);","typeGuard":null,"tryCatchPattern":"try {\n    return SimplificationErrorCalculator.byName(name);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().startsWith(\"Unknown simplification error calculator:\")) {\n        return SimplificationErrorCalculator.TRIANGLE_AREA; // safe default\n    }\n    throw e;\n}","preventionTips":["When wiring code, reference the constants (CARTESIAN_TRIANGLE_AREA, etc.) directly instead of string names.","Validate user-supplied calculator names against the known set at the configuration boundary.","Lowercase and trim the name before matching; case is tolerated but spelling must be exact."],"tags":["geometry","simplification","calculator","configuration","enum-like","libs-geo"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T08:17:17.861Z"}