{"record":{"id":"16fa6ef60541ba4f","repo":"oracle/graal","slug":"could-not-find-method-in-s-named-s","errorCode":null,"errorMessage":"Could not find method in %s named %s","messagePattern":"Could not find method in (.+?) named (.+?)","errorType":"exception","errorClass":"GraalError","httpStatus":null,"severity":"error","filePath":"compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/SnippetTemplate.java","lineNumber":868,"sourceCode":"            this.shouldTrackNodeSourcePosition = providers.getCodeCache() != null && providers.getCodeCache().shouldDebugNonSafepoints();\n        }\n\n        public static ResolvedJavaMethod findMethod(MetaAccessProvider metaAccess, Class<?> declaringClass, String methodName) {\n            ResolvedJavaType type = metaAccess.lookupJavaType(declaringClass);\n            type.link();\n            ResolvedJavaMethod result = null;\n            for (ResolvedJavaMethod m : type.getDeclaredMethods(false)) {\n                if (m.getName().equals(methodName)) {\n                    if (!Assertions.assertionsEnabled()) {\n                        return m;\n                    } else {\n                        assert result == null : \"multiple definitions found\";\n                        result = m;\n                    }\n                }\n            }\n            if (result == null) {\n                throw new GraalError(\"Could not find method in \" + declaringClass + \" named \" + methodName);\n            }\n            return result;\n        }\n\n        /**\n         * Finds the unique method in {@code declaringClass} named {@code methodName} annotated by\n         * {@link Snippet} and returns a {@link SnippetInfo} value describing it. There must be\n         * exactly one snippet method in {@code declaringClass} with a given name.\n         *\n         * The snippet found must have {@link ProfileSource#isTrusted(ProfileSource)} known profiles\n         * for all {@link IfNode} in the {@link StructuredGraph}.\n         */\n        protected SnippetInfo snippet(Providers providers,\n                        Class<? extends Snippets> declaringClass,\n                        String methodName,\n                        LocationIdentity... initialPrivateLocations) {\n            return snippet(providers,\n                            declaringClass,","sourceCodeStart":850,"sourceCodeEnd":886,"githubUrl":"https://github.com/oracle/graal/blob/a66e9ccd1d7bf2552883939aa0788dfd0e294aab/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/SnippetTemplate.java#L850-L886","documentation":"Thrown while SnippetTemplate looks up a snippet method by name in the snippet declaring class. It iterates type.getDeclaredMethods(false) (declared methods only, no superclass) and if no method matches methodName it throws GraalError naming the class and method. It aborts snippet instantiation during lowering, so compilation of any method using that snippet fails.","triggerScenarios":"A snippet lookup (e.g. SnippetTemplate/findSnippetMethod paths, or a replacement plugin referencing a @Snippet method by name string) where methodName does not exist as a declared method of declaringClass: method was renamed, lives only in a superclass, was removed, or declaringClass is the wrong class.","commonSituations":"Renaming a @Snippet method without updating the code that looks it up; copy-pasting a snippet class and changing names; moving a snippet to a base class (getDeclaredMethods(false) will not find it); stale native-image/reflection configuration referencing old names.","solutions":["Check that a method with exactly that name is declared directly in declaringClass (javap or IDE); fix the name string or the class passed in.","If the method is inherited, move it into the declaring class or point the lookup at the class that actually declares it.","After renaming a snippet, grep the repo for the old name string and update all references.","Rebuild the module so the snippet class is not stale in a cached build artifact."],"exampleFix":"// before\nResolvedJavaMethod m = findMethod(MySnippets.class, \"storeFieldOld\");\n\n// after (method was renamed to storeField)\nResolvedJavaMethod m = findMethod(MySnippets.class, \"storeField\");","handlingStrategy":"validation","validationCode":"// Before looking up a snippet method, verify it is declared on the class\nstatic ResolvedJavaMethod findMethodChecked(Class<?> declaringClass, String name) {\n    boolean found = java.util.Arrays.stream(declaringClass.getDeclaredMethods())\n            .anyMatch(m -> m.getName().equals(name));\n    if (!found) {\n        throw new IllegalStateException(\"No method '\" + name + \"' declared in \" + declaringClass.getName()\n                + \" (declared methods only; superclass methods are not visible)\");\n    }\n    return null; // proceed with the real lookup\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["After renaming any @Snippet method, grep for the old name string across the repo before building.","Keep snippet methods declared directly on the snippet class, not inherited from a base class.","In tests, assert that every snippet name referenced by plugins resolves on the snippet class."],"tags":["graal","snippet","method-lookup","renaming","lowering"],"backgroundTag":null,"analyzedSha":"a66e9ccd1d7bf2552883939aa0788dfd0e294aab","analyzedAt":"2026-08-14T13:58:47.161Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}