{"record":{"id":"06de9066fad845c9","repo":"oracle/graal","slug":"invalid-constant","errorCode":null,"errorMessage":"Invalid constant.","messagePattern":"Invalid constant\\.","errorType":"exception","errorClass":"DeserializationException","httpStatus":null,"severity":"error","filePath":"compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/replaycomp/JsonReplayCodec.java","lineNumber":572,"sourceCode":"\n        @Override\n        public void serialize(Object instance, JsonBuilder.ObjectBuilder objectBuilder, RecursiveSerializer serializer) throws IOException {\n            Enum<?> en = (Enum<?>) instance;\n            serializer.serialize(en.getClass(), objectBuilder.append(\"holder\"));\n            objectBuilder.append(\"constant\", en.name());\n        }\n\n        @SuppressWarnings(\"unchecked\")\n        @Override\n        public Object deserialize(EconomicMap<String, Object> json, RecursiveDeserializer deserializer, CompilationProxies.ProxyFactory proxyFactory) throws DeserializationException {\n            Class<? extends Enum<?>> enumClass = (Class<? extends Enum<?>>) deserializer.deserialize(json.get(\"holder\"), proxyFactory);\n            String constantName = (String) json.get(\"constant\");\n            for (Enum<?> constant : enumClass.getEnumConstants()) {\n                if (constant.name().equals(constantName)) {\n                    return constant;\n                }\n            }\n            throw new DeserializationException(this, json, \"Invalid constant.\");\n        }\n    }\n\n    private static final class ArraySerializer implements ObjectSerializer {\n\n        private final CompilerInterfaceDeclarations declarations;\n\n        private ArraySerializer(CompilerInterfaceDeclarations declarations) {\n            this.declarations = declarations;\n        }\n\n        @Override\n        public boolean serializesSubclasses() {\n            return true;\n        }\n\n        @Override\n        public Class<?> clazz() {","sourceCodeStart":554,"sourceCodeEnd":590,"githubUrl":"https://github.com/oracle/graal/blob/a66e9ccd1d7bf2552883939aa0788dfd0e294aab/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/replaycomp/JsonReplayCodec.java#L554-L590","documentation":"EnumSerializer.deserialize resolves an enum constant by name: it loads the enum class (from the 'holder' entry) and scans getEnumConstants() for one whose name() equals the recorded 'constant'. If no constant matches, it throws DeserializationException('Invalid constant.') — the enum exists but the name does not.","triggerScenarios":"Deserializing an enum entry where 'constant' names a value absent from the loaded enum class: enum constant renamed/removed between the recording and replaying GraalVM builds, or a typo in hand-edited JSON.","commonSituations":"Version skew where CPUFeature or phase enums gained/renamed constants; replaying across CPU generations where a CPUFeature enum differs; manual JSON edits.","solutions":["Use identical GraalVM builds for record and replay","Inspect the entry's 'holder' and 'constant' fields (included in the DeserializationException context) and map the old name to the new one","If replaying across versions is required, add a name-alias mapping in EnumSerializer before throwing"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Pre-check the constant name against the enum before full replay\nClass<? extends Enum<?>> ec = loadEnumClass(holderName);\nboolean ok = Arrays.stream(ec.getEnumConstants()).anyMatch(c -> c.name().equals(constantName));\nif (!ok) throw new IllegalArgumentException(\"Enum \" + holderName + \" has no constant \" + constantName);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Match GraalVM versions between record and replay so enum constants align","If cross-version replay is required, maintain an alias table mapping removed/renamed enum constants"],"tags":["graalvm","replay","deserialization","enum"],"backgroundTag":null,"analyzedSha":"a66e9ccd1d7bf2552883939aa0788dfd0e294aab","analyzedAt":"2026-08-14T13:58:47.161Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}