{"record":{"id":"d37245bf0fee8daf","repo":"oracle/graal","slug":"unknown-enum-constant-for","errorCode":null,"errorMessage":"Unknown enum constant  for ","messagePattern":"Unknown enum constant  for ","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/replaycomp/BinaryReplayCodec.java","lineNumber":851,"sourceCode":"            case STRING_TAG -> readStringReference(in, state);\n            case SPECIAL_SINGLETON_TAG -> readSpecialSingleton(in.readPackedUnsignedInt());\n            case REGISTERED_SINGLETON_TAG -> state.singletonProxy(in.readPackedUnsignedInt());\n            case REGISTERED_INSTANCE_TAG -> state.instanceProxy(in.readPackedUnsignedInt(), in.readPackedUnsignedInt());\n            case CLASS_TAG -> ReplayTypeSupport.decodeClass(requireNonNullString(readStringReference(in, state), \"class name\"));\n            case ENUM_TAG -> {\n                var enumClass = (Class<? extends Enum<?>>) (Class<?>) ReplayTypeSupport.classCast(\n                                ReplayTypeSupport.decodeClass(requireNonNullString(readStringReference(in, state), \"enum class\")));\n                String constantName = requireNonNullString(readStringReference(in, state), \"enum constant\");\n                Enum<?>[] constants = enumClass.getEnumConstants();\n                Enum<?> match = null;\n                for (Enum<?> constant : constants) {\n                    if (constant.name().equals(constantName)) {\n                        match = constant;\n                        break;\n                    }\n                }\n                if (match == null) {\n                    throw new IOException(\"Unknown enum constant \" + constantName + \" for \" + enumClass.getName());\n                }\n                yield match;\n            }\n            case OBJECT_ARRAY_TAG -> {\n                Class<?> component = ReplayTypeSupport.classCast(readValue(in, state));\n                int length = in.readPackedUnsignedInt();\n                Object[] array = (Object[]) Array.newInstance(component, length);\n                for (int i = 0; i < length; i++) {\n                    array[i] = readValue(in, state);\n                }\n                yield array;\n            }\n            case LIST_TAG -> {\n                int length = in.readPackedUnsignedInt();\n                ArrayList<Object> list = new ArrayList<>(length);\n                for (int i = 0; i < length; i++) {\n                    list.add(readValue(in, state));\n                }","sourceCodeStart":833,"sourceCodeEnd":869,"githubUrl":"https://github.com/oracle/graal/blob/a66e9ccd1d7bf2552883939aa0788dfd0e294aab/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/replaycomp/BinaryReplayCodec.java#L833-L869","documentation":"Thrown during replay decoding when an enum value is read: the codec decodes the enum class and constant name from the stream, then linearly searches getEnumConstants() for a matching name. If the enum in the replaying JVM has no constant with the recorded name, it fails with IOException 'Unknown enum constant <name> for <class>'. This is the standard failure mode for record/replay across JVMs whose enum definitions differ.","triggerScenarios":"Replaying a file recorded on a GraalVM build where the enum had a constant that was renamed or removed in the replaying build; replaying a truncated or corrupted stream where the constant-name string reference resolves incorrectly.","commonSituations":"Version skew between the recording and replaying GraalVM/compiler builds; replaying files produced by a development branch with extra enum constants; classpath differences that load a different enum version.","solutions":["Re-record the replay file with the same GraalVM/compiler build used for replay","Verify the enum constant still exists in the replaying build (grep the enum source) and update to a build where it does","If the stream may be corrupt, re-generate or re-transfer the replay file and retry"],"exampleFix":"// before\nEnum<?> e = (Enum<?>) readValue(in, state); // IOException: Unknown enum constant FOO for Bar\n\n// after\n// pre-check before decoding if you control the format knowledge\nClass<? extends Enum<?>> ec = loadEnumClass();\nboolean present = Arrays.stream(ec.getEnumConstants()).anyMatch(c -> c.name().equals(expectedName));\nif (!present) throw new IOException(\"Enum constant missing, re-record replay file\");","handlingStrategy":"try-catch","validationCode":"<E extends Enum<E>> boolean hasConstant(Class<E> ec, String name) {\n    for (E c : ec.getEnumConstants()) if (c.name().equals(name)) return true;\n    return false;\n}","typeGuard":null,"tryCatchPattern":"try {\n    result = codec.readReplay(in);\n} catch (IOException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"Unknown enum constant\")) {\n        // enum skew between record and replay builds: re-record on this build\n    } else throw e;\n}","preventionTips":["Record and replay with the same GraalVM and JDK builds","Treat enum additions/removals as replay-format changes: re-record after any build change touching enums used in recorded state"],"tags":["graalvm","replay-compilation","deserialization","enum","version-skew"],"backgroundTag":null,"analyzedSha":"a66e9ccd1d7bf2552883939aa0788dfd0e294aab","analyzedAt":"2026-08-14T13:58:47.161Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}