{"record":{"id":"8cf89a2e818f1f56","repo":"elastic/elasticsearch","slug":"cannot-apply-operation-to-type-float-8cf89a","errorCode":null,"errorMessage":"Cannot apply [>>>] operation to type [float]","messagePattern":"Cannot apply \\[>>>\\] operation to type \\[float\\]","errorType":"exception","errorClass":"ClassCastException","httpStatus":null,"severity":"error","filePath":"modules/lang-painless/src/main/java/org/elasticsearch/painless/DefMath.java","lineNumber":1052,"sourceCode":"\n    public static Object rsh(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    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","sourceCodeStart":1034,"sourceCodeEnd":1070,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/modules/lang-painless/src/main/java/org/elasticsearch/painless/DefMath.java#L1034-L1070","documentation":"Painless throws this ClassCastException at runtime when the unsigned right-shift (>>>) operator is applied to a float value through the def/dynamic path. DefMath.ush(float, long) is a throwing stub: >>> is a bitwise operation and has no defined result on IEEE-754 floats. Only the int and long overloads of ush compute the shift; the float/double/boolean stubs exist to give the dynamic dispatcher a readable failure for every promoted type.","triggerScenarios":"A def variable holding a float is used with >>>: 'def x = 2.5f; def y = x >>> 2;'. The Object-dispatch ush(Object, long) eventually selects the float stub and throws.","commonSituations":"Scripts doing bitmask/flag extraction on def-typed values sourced from float-mapped doc fields. Porting bit-twiddling code that assumed integer storage. Runtime fields that produce float results fed into shift logic.","solutions":["Cast to int or long before the shift: '((long) x) >>> 2'.","Replace def with an explicit integral type so the compiler catches the mismatch.","If the value is genuinely floating-point, replace the bitwise shift with the appropriate arithmetic equivalent."],"exampleFix":"// before\ndef x = doc['ratio'].value;  // float field\ndef y = x >>> 4;\n// after\nint x = (int) doc['ratio'].value;\nint y = x >>> 4;","handlingStrategy":"type-guard","validationCode":"// Cast to long before unsigned right shift:\n// def x = doc['ratio'].value;\n// long y = ((long) x) >>> 4;","typeGuard":"// boolean isIntegral = x instanceof Integer || x instanceof Long || x instanceof Short || x instanceof Byte;","tryCatchPattern":null,"preventionTips":["Always cast def values to int/long before >>>.","Avoid def for shift operations; use explicit types.","Verify field types before applying bitwise logic."],"tags":["painless","elasticsearch","type-error","bitwise","def-typing","runtime"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T11:17:21.771Z"}