{"record":{"id":"76d68137c01b5b38","repo":"oracle/graal","slug":"illegal-call-to-bits-on","errorCode":null,"errorMessage":"illegal call to bits on ","messagePattern":"illegal call to bits on ","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"espresso-shared/src/com.oracle.truffle.espresso.classfile/src/com/oracle/truffle/espresso/classfile/JavaKind.java","lineNumber":410,"sourceCode":"    public int getBitCount() {\n        switch (this) {\n            case Boolean:\n                return 1;\n            case Byte:\n                return 8;\n            case Char:\n            case Short:\n                return 16;\n            case Float:\n                return 32;\n            case Int:\n                return 32;\n            case Double:\n                return 64;\n            case Long:\n                return 64;\n            default:\n                throw new IllegalArgumentException(\"illegal call to bits on \" + this);\n        }\n    }\n\n    /**\n     * Returns the Espresso type (symbol) of this kind.\n     *\n     * @return the Espresso type (symbol) of this kind\n     */\n    public Symbol<Type> getType() {\n        return type;\n    }\n\n    public Symbol<Name> getPrimitiveBinaryName() {\n        ErrorUtil.guarantee(isPrimitive(), \"not a primitive\");\n        return name;\n    }\n\n    public String getUnwrapMethodName() {","sourceCodeStart":392,"sourceCodeEnd":428,"githubUrl":"https://github.com/oracle/graal/blob/a66e9ccd1d7bf2552883939aa0788dfd0e294aab/espresso-shared/src/com.oracle.truffle.espresso.classfile/src/com/oracle/truffle/espresso/classfile/JavaKind.java#L392-L428","documentation":"JavaKind.getBitCount returns the bit width of a numeric kind (16 for Char/Short, 32 for Float/Int, 64 for Double/Long). Boolean, Void, Illegal, and Object are not in the switch, so calling getBitCount on them throws IllegalArgumentException 'illegal call to bits on <kind>'.","triggerScenarios":"Calling getBitCount() on JavaKind.Boolean, Void, Illegal, or Object — e.g. generic sizing code computing slot widths or struct layouts over all kinds.","commonSituations":"Word/slot size computations that assume every kind has a bit width (Boolean is 1 byte but has no 'bits' entry here); table generation over JavaKind.values(); ports of Graal compiler code where the guard was lost.","solutions":["Special-case Boolean (use getByteCount() == 1) and skip Object/Void/Illegal before calling getBitCount()","Restrict calls to kind.isPrimitive() && kind != JavaKind.Void && kind != JavaKind.Boolean"],"exampleFix":"// before\nint bits = kind.getBitCount(); // fails for Boolean/Void/Object/Illegal\n\n// after\nint bits = (kind == JavaKind.Boolean) ? 1 : (kind.isPrimitive() && kind != JavaKind.Void) ? kind.getBitCount() : -1;","handlingStrategy":"type-guard","validationCode":"if (!kind.isPrimitive() || kind == JavaKind.Void || kind == JavaKind.Boolean) throw new IllegalArgumentException(\"no bit count for \" + kind);","typeGuard":"static boolean hasBitCount(JavaKind k) { return k.isPrimitive() && k != JavaKind.Void && k != JavaKind.Boolean; }","tryCatchPattern":null,"preventionTips":["Remember Boolean is sized via getByteCount() (1 byte), not getBitCount()","Use one shared guard for all numeric-kind accessors to avoid per-accessor drift"],"tags":["espresso","classfile","javakind","enum"],"backgroundTag":null,"analyzedSha":"a66e9ccd1d7bf2552883939aa0788dfd0e294aab","analyzedAt":"2026-08-14T13:58:47.161Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}