elastic/elasticsearch · error · ClassCastException

Cannot apply [>>>] operation to type [double]

Error message

Cannot apply [>>>] operation to type [double]

What it means

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.

Source

Thrown at modules/lang-painless/src/main/java/org/elasticsearch/painless/DefMath.java:1056

        } else {
            return intIntegralValue(left) >> right;
        }
    }

    private static int ush(int a, long b) {
        return a >>> b;
    }

    private static long ush(long a, long b) {
        return a >>> b;
    }

    private static float ush(float a, long b) {
        throw new ClassCastException("Cannot apply [>>>] operation to type [float]");
    }

    private static double ush(double a, long b) {
        throw new ClassCastException("Cannot apply [>>>] operation to type [double]");
    }

    private static boolean ush(boolean a, long b) {
        throw new ClassCastException("Cannot apply [>>>] operation to type [boolean]");
    }

    public static Object ush(Object left, long right) {
        if (left instanceof Long) {
            return (long) (left) >>> right;
        } else {
            return intIntegralValue(left) >>> right;
        }
    }

    /**
     * unboxes a class to its primitive type, or returns the original
     * class if its not a boxed type.
     */

View on GitHub (pinned to db6a809a66)

Solutions

  1. Cast to long or int first: '((long) x) >>> 1'.
  2. Use an explicit integral type declaration instead of def.
  3. Replace the shift with arithmetic if the operand is genuinely continuous.

Example fix

// before
def x = doc['price'].value;  // double
def y = x >>> 2;
// after
long x = (long) doc['price'].value;
long y = x >>> 2;
Defensive patterns

Strategy: type-guard

Validate before calling

// Cast double to long before >>>:
// def x = doc['price'].value;
// long y = ((long) x) >>> 2;

Type guard

// boolean isIntegral = x instanceof Integer || x instanceof Long || x instanceof Short || x instanceof Byte;

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12). Data as JSON: /api/errors/045df2b63a5ac2c7. Report an issue: GitHub.