{"record":{"id":"045df2b63a5ac2c7","repo":"elastic/elasticsearch","slug":"cannot-apply-operation-to-type-double-045df2","errorCode":null,"errorMessage":"Cannot apply [>>>] operation to type [double]","messagePattern":"Cannot apply \\[>>>\\] operation to type \\[double\\]","errorType":"exception","errorClass":"ClassCastException","httpStatus":null,"severity":"error","filePath":"modules/lang-painless/src/main/java/org/elasticsearch/painless/DefMath.java","lineNumber":1056,"sourceCode":"        } else {\n            return intIntegralValue(left) >> right;\n        }\n    }\n\n    private static int ush(int a, long b) {\n        return a >>> b;\n    }\n\n    private static long ush(long a, long b) {\n        return a >>> b;\n    }\n\n    private static float ush(float a, long b) {\n        throw new ClassCastException(\"Cannot apply [>>>] operation to type [float]\");\n    }\n\n    private static double ush(double a, long b) {\n        throw new ClassCastException(\"Cannot apply [>>>] operation to type [double]\");\n    }\n\n    private static boolean ush(boolean a, long b) {\n        throw new ClassCastException(\"Cannot apply [>>>] operation to type [boolean]\");\n    }\n\n    public static Object ush(Object left, long right) {\n        if (left instanceof Long) {\n            return (long) (left) >>> right;\n        } else {\n            return intIntegralValue(left) >>> right;\n        }\n    }\n\n    /**\n     * unboxes a class to its primitive type, or returns the original\n     * class if its not a boxed type.\n     */","sourceCodeStart":1038,"sourceCodeEnd":1074,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/modules/lang-painless/src/main/java/org/elasticsearch/painless/DefMath.java#L1038-L1074","documentation":"Painless throws this ClassCastException at runtime when the unsigned right-shift (>>>) is applied to a double through the def/dynamic path. DefMath.ush(double, long) is a stub that always throws because bitwise operations are undefined on IEEE-754 doubles. The double overload exists only so TYPE_OP_MAPPING has a uniform handle for every promoted type, producing a clear error instead of a dispatch failure.","triggerScenarios":"A def variable resolves to double at runtime and is shifted with >>>: 'def x = 1.0; def y = x >>> 1;'. Routes through ush(Object, long) into the double stub.","commonSituations":"Doc fields mapped as double, results of division or math functions that widen to double, or scripts that treat all numeric def values uniformly with bit logic.","solutions":["Cast to long or int first: '((long) x) >>> 1'.","Use an explicit integral type declaration instead of def.","Replace the shift with arithmetic if the operand is genuinely continuous."],"exampleFix":"// before\ndef x = doc['price'].value;  // double\ndef y = x >>> 2;\n// after\nlong x = (long) doc['price'].value;\nlong y = x >>> 2;","handlingStrategy":"type-guard","validationCode":"// Cast double to long before >>>:\n// def x = doc['price'].value;\n// long y = ((long) x) >>> 2;","typeGuard":"// boolean isIntegral = x instanceof Integer || x instanceof Long || x instanceof Short || x instanceof Byte;","tryCatchPattern":null,"preventionTips":["Cast def values to long before unsigned shifts.","Use typed variables for bit operations.","Check that source fields are integral before shifting."],"tags":["painless","elasticsearch","type-error","bitwise","def-typing","runtime"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T08:17:17.861Z"}