oracle/graal · error · GraalError
Could not find method in %s named %s
Error message
Could not find method in %s named %s
What it means
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.
Source
Thrown at compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/SnippetTemplate.java:868
this.shouldTrackNodeSourcePosition = providers.getCodeCache() != null && providers.getCodeCache().shouldDebugNonSafepoints();
}
public static ResolvedJavaMethod findMethod(MetaAccessProvider metaAccess, Class<?> declaringClass, String methodName) {
ResolvedJavaType type = metaAccess.lookupJavaType(declaringClass);
type.link();
ResolvedJavaMethod result = null;
for (ResolvedJavaMethod m : type.getDeclaredMethods(false)) {
if (m.getName().equals(methodName)) {
if (!Assertions.assertionsEnabled()) {
return m;
} else {
assert result == null : "multiple definitions found";
result = m;
}
}
}
if (result == null) {
throw new GraalError("Could not find method in " + declaringClass + " named " + methodName);
}
return result;
}
/**
* Finds the unique method in {@code declaringClass} named {@code methodName} annotated by
* {@link Snippet} and returns a {@link SnippetInfo} value describing it. There must be
* exactly one snippet method in {@code declaringClass} with a given name.
*
* The snippet found must have {@link ProfileSource#isTrusted(ProfileSource)} known profiles
* for all {@link IfNode} in the {@link StructuredGraph}.
*/
protected SnippetInfo snippet(Providers providers,
Class<? extends Snippets> declaringClass,
String methodName,
LocationIdentity... initialPrivateLocations) {
return snippet(providers,
declaringClass,View on GitHub (pinned to a66e9ccd1d)
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.
Example fix
// before ResolvedJavaMethod m = findMethod(MySnippets.class, "storeFieldOld"); // after (method was renamed to storeField) ResolvedJavaMethod m = findMethod(MySnippets.class, "storeField");
Defensive patterns
Strategy: validation
Validate before calling
// Before looking up a snippet method, verify it is declared on the class
static ResolvedJavaMethod findMethodChecked(Class<?> declaringClass, String name) {
boolean found = java.util.Arrays.stream(declaringClass.getDeclaredMethods())
.anyMatch(m -> m.getName().equals(name));
if (!found) {
throw new IllegalStateException("No method '" + name + "' declared in " + declaringClass.getName()
+ " (declared methods only; superclass methods are not visible)");
}
return null; // proceed with the real lookup
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Can't store into VarargsParameter array
- too many arguments
- Too deep inlining, probably caused by recursive inlining.
- INVOKEDYNAMIC not supported by %s
- INVOKEDYNAMIC not supported by%s
AI-assisted analysis of oracle/graal@a66e9ccd1d (2026-08-14).
Data as JSON: /api/errors/16fa6ef60541ba4f.
Report an issue: GitHub.