{"record":{"id":"5a7a29b75ab0cf6c","repo":"karatelabs/karate","slug":"bigints-have-no-unsigned-right-shift-use-instead","errorCode":null,"errorMessage":"BigInts have no unsigned right shift, use >> instead","messagePattern":"BigInts have no unsigned right shift, use >> instead","errorType":"exception","errorClass":"JsErrorException (typeError)","httpStatus":null,"severity":"error","filePath":"karate-js/src/main/java/io/karatelabs/js/Terms.java","lineNumber":723,"sourceCode":"        Number lhs = toNumericOperand(lhsObject, context);\n        if (context != null && context.isError()) return UNDEFINED;\n        Number rhs = toNumericOperand(rhsObject, context);\n        if (context != null && context.isError()) return UNDEFINED;\n        if (isBigIntOp(lhs, rhs)) {\n            requireBothBigInt(lhs, rhs, \"<<\");\n            return narrowBigInt(((BigInteger) lhs).shiftLeft(((BigInteger) rhs).intValueExact()));\n        }\n        return lhs.intValue() << rhs.intValue();\n    }\n\n    static Object bitShiftRightUnsigned(Object lhsObject, Object rhsObject, CoreContext context) {\n        Number lhs = toNumericOperand(lhsObject, context);\n        if (context != null && context.isError()) return UNDEFINED;\n        Number rhs = toNumericOperand(rhsObject, context);\n        if (context != null && context.isError()) return UNDEFINED;\n        if (isBigIntOp(lhs, rhs)) {\n            // spec: unsigned right shift on BigInt always TypeError, even when both operands are BigInt\n            throw JsErrorException.typeError(\"BigInts have no unsigned right shift, use >> instead\");\n        }\n        return narrow((lhs.intValue() & 0xFFFFFFFFL) >>> rhs.intValue());\n    }\n\n    static Object bitNot(Object value, CoreContext context) {\n        Number number = toNumericOperand(value, context);\n        if (context != null && context.isError()) return UNDEFINED;\n        if (number instanceof BigInteger bi) {\n            return narrowBigInt(bi.not());\n        }\n        return ~number.intValue();\n    }\n\n    static Object mul(Object lhsObject, Object rhsObject, CoreContext context) {\n        Number lhs = toNumericOperand(lhsObject, context);\n        if (context != null && context.isError()) return UNDEFINED;\n        Number rhs = toNumericOperand(rhsObject, context);\n        if (context != null && context.isError()) return UNDEFINED;","sourceCodeStart":705,"sourceCodeEnd":741,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-js/src/main/java/io/karatelabs/js/Terms.java#L705-L741","documentation":"A TypeError implementing the spec rule that BigInt has no unsigned right shift operator: `>>>` always throws for BigInt operands, even when both sides are BigInt, because the semantics are undefined for arbitrary-precision integers. The message tells you to use the signed `>>` instead.","triggerScenarios":"Evaluating `a >>> b` in the embedded JS engine where `a` or `b` is a BigInt/BigInteger (isBigIntOp true), regardless of whether the other operand is a plain number.","commonSituations":"Porting bit-manipulation JavaScript that uses `>>>` for hashing/parsing into Karate JS while feeding BigInt values (e.g. from Java bridges or `BigInt()` conversions).","solutions":["Replace `>>>` with the signed `>>` when operands are BigInt and the values fit the signed range.","Convert operands to Numbers before `>>>` when the values fit in 32 bits: `Number(a) >>> Number(b)`.","Restructure the algorithm to avoid unsigned shift on BigInt (e.g. mask with BigInt: `a & 0xFFFFFFFFn` then `>>`).","Keep BigInt values out of hashing code paths; do those computations in Java helpers instead."],"exampleFix":"// before\n* eval hash = bigIntValue >>> 16\n// after\n* eval hash = bigIntValue >> 16n\n// or, if it fits 32 bits:\n* eval hash = Number(bigIntValue) >>> 16","handlingStrategy":"type-guard","validationCode":"if (typeof a === 'bigint' || typeof b === 'bigint') { /* use >> or mask */ } else { result = a >>> b; }","typeGuard":"function usesBigInt(a, b) { return typeof a === 'bigint' || typeof b === 'bigint'; }","tryCatchPattern":null,"preventionTips":["Ban >>> in BigInt code paths; use >> plus masking instead.","Convert to Number when values fit 32 bits before unsigned shifts.","Review ported hashing code for unsigned-shift idioms.","Keep BigInt isolated to big-number logic; hash with plain numbers."],"tags":["javascript","type-error","bigint","bitwise-operators"],"backgroundTag":"unsupported-operation","analyzedSha":"a22eb90246d958d15a47bf436693d0121ad2812d","analyzedAt":"2026-09-12T09:01:00.220Z","contentChangedAt":"2026-09-12T09:01:00.220Z","schemaVersion":2},"datasetVersion":"2026-09-16T19:17:19.609Z"}