NationalSecurityAgency/ghidra · error · IllegalArgumentException
Service receiver method may take only one parameter
Error message
Service receiver method may take only one parameter
What it means
Thrown by AutoServiceListener.MethodServiceSetter when a method annotated @AutoServiceConsumed does not take exactly one parameter. The framework injects a service by invoking the method with the service instance, so the method must declare exactly one parameter whose type is the service interface. Zero, two, or more parameters are rejected at setter-construction time.
Source
Thrown at Ghidra/Debug/ProposedUtils/src/main/java/ghidra/framework/plugintool/util/AutoServiceListener.java:74
}
}
@Override
public Class<S> getServiceIface() {
return iface;
}
}
protected static class MethodServiceSetter<R, S> implements ServiceSetter<R, S> {
protected final Method method;
protected final Class<S> iface;
@SuppressWarnings("unchecked")
public MethodServiceSetter(Method method) {
this.method = method;
Class<?>[] types = method.getParameterTypes();
if (types.length != 1) {
throw new IllegalArgumentException(
"Service receiver method may take only one parameter");
}
this.iface = (Class<S>) types[0];
method.setAccessible(true);
}
@Override
public void set(R receiver, S service) {
try {
method.invoke(receiver, service);
}
catch (IllegalAccessException | IllegalArgumentException e) {
throw new AssertionError(e);
}
catch (InvocationTargetException e) {
Throwable cause = e.getCause();
if (cause instanceof RuntimeException) {View on GitHub (pinned to d5f144c24d)
Solutions
- Give the @AutoServiceConsumed method exactly one parameter typed as the service interface to receive.
- Move extra inputs into receiver fields or obtain them inside the method body.
- Remove @AutoServiceConsumed from methods that are not single-service receivers.
Example fix
// before
@AutoServiceConsumed
public void onService(MyService svc, PluginTool tool) { ... } // 2 params
// after
@AutoServiceConsumed
public void onService(MyService svc) {
doWith(this.tool, svc);
} Defensive patterns
Strategy: validation
Validate before calling
if (method.getParameterCount() != 1) {
throw new IllegalStateException(
"@AutoServiceConsumed method must take exactly one param: " + method);
} Prevention
- Give each @AutoServiceConsumed method exactly one parameter.
- Obtain extra context from receiver fields, not parameters.
- Scan for mis-annotated methods in a wiring unit test.
When it happens
Trigger: An @AutoServiceConsumed method with no parameters, or with two or more. Adding extra parameters (e.g. a context or a flag) beyond the service. A void no-arg method mistakenly annotated as a service consumer.
Common situations: Refactoring a service receiver to take additional arguments; annotating an initialization method that takes no args; copy-paste of an annotation onto a method with the wrong shape.
Related errors
- {}-annotated method {} cannot have more than two parameters
- Could not determine option type from default value: {} = {}
- Cannot apply {} to both parameters of {}
- Unsupported value: {}
- Invalid value for {}
AI-assisted analysis of NationalSecurityAgency/ghidra@d5f144c24d (2026-08-14).
Data as JSON: /api/errors/10f22321cfa96e7f.
Report an issue: GitHub.