{"record":{"id":"67d087c9c4e95a91","repo":"oracle/graal","slug":"invalid-ordinal-ordinal-for-enumclassname","errorCode":null,"errorMessage":"Invalid ordinal ${ordinal} for ${enumClassName}","messagePattern":"Invalid ordinal (.+?) for (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/replaycomp/BinaryReplayCodec.java","lineNumber":1180,"sourceCode":"            default -> throw new IOException(\"Unknown replay architecture kind\");\n        };\n    }\n\n    private static void writeEnumOrdinals(ObjectCopierOutputStream out, EnumSet<?> enumSet) throws IOException {\n        out.writePackedUnsignedInt(enumSet.size());\n        for (Enum<?> constant : enumSet) {\n            out.writePackedUnsignedInt(constant.ordinal());\n        }\n    }\n\n    private static <E extends Enum<E>> EnumSet<E> readEnumOrdinals(ObjectCopierInputStream in, Class<E> enumClass) throws IOException {\n        int size = in.readPackedUnsignedInt();\n        EnumSet<E> enumSet = EnumSet.noneOf(enumClass);\n        E[] constants = enumClass.getEnumConstants();\n        for (int i = 0; i < size; i++) {\n            int ordinal = in.readPackedUnsignedInt();\n            if (ordinal < 0 || ordinal >= constants.length) {\n                throw new IOException(\"Invalid ordinal \" + ordinal + \" for \" + enumClass.getName());\n            }\n            enumSet.add(constants[ordinal]);\n        }\n        return enumSet;\n    }\n\n    private static int registerConfigKind(RegisterConfig registerConfig) {\n        return switch (registerConfig) {\n            case AMD64HotSpotRegisterConfig ignored -> AMD64_ARCHITECTURE;\n            case RISCV64HotSpotRegisterConfig ignored -> RISCV64_ARCHITECTURE;\n            case AArch64HotSpotRegisterConfig ignored -> AARCH64_ARCHITECTURE;\n            default -> throw new IllegalArgumentException(\"Unexpected register config \" + registerConfig);\n        };\n    }\n\n    @SuppressWarnings(\"unchecked\")\n    private static RegisterConfig readRegisterConfig(ObjectCopierInputStream in, ReadState state) throws IOException {\n        int kind = in.readPackedUnsignedInt();","sourceCodeStart":1162,"sourceCodeEnd":1198,"githubUrl":"https://github.com/oracle/graal/blob/a66e9ccd1d7bf2552883939aa0788dfd0e294aab/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/replaycomp/BinaryReplayCodec.java#L1162-L1198","documentation":"readEnumOrdinals rebuilds an EnumSet from ordinal integers, bounds-checking each ordinal against enumClass.getEnumConstants().length. An ordinal outside [0, length) throws IOException 'Invalid ordinal <ordinal> for <enum class>'. This is the classic record/replay enum-skew failure: the recording JVM's enum had more constants (or a different order) than the replaying JVM's.","triggerScenarios":"Replaying CPU feature sets or other enum sets recorded on a build where the enum had extra/reordered constants; corrupted packed ints in a feature list.","commonSituations":"JDK or GraalVM upgrade between record and replay that changed a CPUFeature enum (e.g. new CPU features appended then removed); cross-build replay of architecture descriptions.","solutions":["Re-record the replay file on the same JDK/GraalVM build used for replay","Check enum constant counts match: recording build's CPUFeature.values().length must equal the replaying build's","If a constant was only appended (no reorder) and the reader is older, upgrade the reader to a build containing the extra constants"],"exampleFix":"// before\nEnumSet<AMD64.CPUFeature> fs = readEnumOrdinals(in, AMD64.CPUFeature.class);\n\n// after\n// pre-flight compatibility check before replay\nint recordedMax = maxRecordedOrdinal(file);\nif (recordedMax >= AMD64.CPUFeature.values().length) {\n    throw new IOException(\"CPUFeature enum skew: re-record replay file on this build\");\n}","handlingStrategy":"validation","validationCode":"static <E extends Enum<E>> boolean ordinalsInRange(Class<E> ec, int... ords) {\n    int n = ec.getEnumConstants().length;\n    for (int o : ords) if (o < 0 || o >= n) return false;\n    return true;\n}","typeGuard":null,"tryCatchPattern":"try {\n    result = codec.readReplay(in);\n} catch (IOException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"Invalid ordinal\")) {\n        // enum skew (e.g. CPUFeature changed): re-record on this build\n    } else throw e;\n}","preventionTips":["Record and replay on the same JDK/GraalVM build so CPUFeature and other enums are identical","Re-record replay files after any JDK upgrade that touches CPU feature enums"],"tags":["graalvm","replay-compilation","enum","cpu-features","version-skew"],"backgroundTag":null,"analyzedSha":"a66e9ccd1d7bf2552883939aa0788dfd0e294aab","analyzedAt":"2026-08-14T13:58:47.161Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}