{"record":{"id":"57fc07f6eca78c5c","repo":"oracle/graal","slug":"invokedynamic-not-supported-by-s","errorCode":null,"errorMessage":"INVOKEDYNAMIC not supported by %s","messagePattern":"INVOKEDYNAMIC not supported by (.+?)","errorType":"exception","errorClass":"GraalError","httpStatus":null,"severity":"error","filePath":"compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/classfile/ClassfileConstantPool.java","lineNumber":151,"sourceCode":"                return new ClassfileConstant.Unsupported(tag, \"CONSTANT_InvokeDynamic_info\");\n            default:\n                throw new ClassFormatError(\"Invalid constant pool tag: \" + tag);\n        }\n    }\n\n    @Override\n    public int length() {\n        return entries.length;\n    }\n\n    <T extends ClassfileConstant> T get(Class<T> c, int index) {\n        return c.cast(entries[index]);\n    }\n\n    @Override\n    public void loadReferencedType(int index, int opcode) {\n        if (opcode == Bytecodes.INVOKEDYNAMIC) {\n            throw new GraalError(\"INVOKEDYNAMIC not supported by \" + ClassfileBytecodeProvider.class.getSimpleName());\n        }\n        entries[index].loadReferencedType(this, index, opcode);\n    }\n\n    @Override\n    public JavaField lookupField(int index, ResolvedJavaMethod method, int opcode) {\n        return get(FieldRef.class, index).resolve(this, opcode);\n    }\n\n    @Override\n    public JavaMethod lookupMethod(int index, int opcode) {\n        if (opcode == Bytecodes.INVOKEDYNAMIC) {\n            throw new GraalError(\"INVOKEDYNAMIC not supported by\" + ClassfileBytecodeProvider.class.getSimpleName());\n        }\n        return get(ExecutableRef.class, index).resolve(this, opcode);\n    }\n\n    @Override","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/oracle/graal/blob/a66e9ccd1d7bf2552883939aa0788dfd0e294aab/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/classfile/ClassfileConstantPool.java#L133-L169","documentation":"ClassfileBytecodeProvider parses snippet classes with its own resolver that has no bootstrap-method machinery, so it cannot link invokedynamic sites. loadReferencedType throws GraalError as soon as an INVOKEDYNAMIC opcode touches the constant pool during eager type loading of a parsed class.","triggerScenarios":"A snippet/replacement class (or anything parsed via ClassfileBytecodeProvider) contains an invokedynamic: lambda, method reference, JDK 9+ string concatenation, or switch-expression desugaring.","commonSituations":"Writing 'nice' modern Java inside @Snippet methods: x -> ..., this::helper, or \"value: \" + v. Snippets are re-parsed from class files through this provider, and all indy forms fail.","solutions":["Replace lambdas/method references in snippet code with anonymous inner classes or plain helper method calls.","Replace '+' string concatenation with StringBuilder.append(...) or explicit String.valueOf/concat calls.","Avoid switch expressions / other indy-based sugar in snippet bodies."],"exampleFix":"// before (inside a @Snippet method)\nString msg = \"count: \" + c;\n\n// after\nString msg = new StringBuilder(\"count: \").append(c).toString();","handlingStrategy":"validation","validationCode":"// Detect invokedynamic/indy-family constants in a snippet class before Graal parses it\nstatic boolean snippetClassIsSafe(Class<?> snippetClass) throws java.io.IOException {\n    String res = '/' + snippetClass.getName().replace('.', '/') + \".class\";\n    try (var in = snippetClass.getResourceAsStream(res)) {\n        var bytes = in.readAllBytes();\n        // crude scan: tag bytes 15..18 outside attribute regions are best checked with ASM:\n        // new ClassReader(bytes).accept(new CheckNoIndyVisitor(), 0);\n        return !new String(java.util.Base64.getEncoder().encode(bytes)).isEmpty(); // placeholder: use ASM\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep snippet bodies on a conservative Java subset: no lambdas, no method references, no '+' string concat, no switch expressions.","Add a build-time check (javap -c | grep invokedynamic) over snippet classes in CI.","Use StringBuilder.append explicitly for any concatenation inside @Snippet code."],"tags":["graal","snippet","invokedynamic","lambda","string-concat"],"backgroundTag":null,"analyzedSha":"a66e9ccd1d7bf2552883939aa0788dfd0e294aab","analyzedAt":"2026-08-14T13:58:47.161Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}