{"record":{"id":"ea7e15c54ca60dd0","repo":"NationalSecurityAgency/ghidra","slug":"annotated-method-cannot-have-more-than-two-p","errorCode":null,"errorMessage":"{}-annotated method {} cannot have more than two parameters","messagePattern":"(.+?)-annotated method (.+?) cannot have more than two parameters","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"Ghidra/Debug/ProposedUtils/src/main/java/ghidra/framework/options/AutoOptionsListener.java","lineNumber":157,"sourceCode":"\t\t\t\t}\n\t\t\t\telse if (parameters[0].getAnnotation(OldValue.class) != null) {\n\t\t\t\t\tif (parameters[1].getAnnotation(OldValue.class) != null) {\n\t\t\t\t\t\tthrow new IllegalArgumentException(\"Cannot apply \" +\n\t\t\t\t\t\t\tOldValue.class.getName() + \" to both parameters of \" + method);\n\t\t\t\t\t}\n\t\t\t\t\tthis.order = ParamOrder.OLD_NEW;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tif (parameters[1].getAnnotation(NewValue.class) != null) {\n\t\t\t\t\t\tthis.order = ParamOrder.OLD_NEW;\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tthis.order = ParamOrder.NEW_OLD;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tthrow new IllegalArgumentException(AutoOptionConsumed.class + \"-annotated method \" +\n\t\t\t\t\tmethod + \" cannot have more than two parameters\");\n\t\t\t}\n\t\t}\n\n\t\t@Override\n\t\tpublic void set(R receiver, Object newValue, Object oldValue) {\n\t\t\tObject[] args = order.populate(oldValue, newValue);\n\t\t\ttry {\n\t\t\t\tmethod.invoke(receiver, args);\n\t\t\t}\n\t\t\tcatch (IllegalArgumentException | IllegalAccessException e) {\n\t\t\t\tString argsStr = StringUtils.join(args, \",\");\n\t\t\t\t// Don't throw, so other consumers get updated\n\t\t\t\tMsg.error(this,\n\t\t\t\t\t\"Could not invoke \" + method + \"(\" + argsStr + \") for option \" + key, e);\n\t\t\t}\n\t\t\tcatch (InvocationTargetException e) {\n\t\t\t\tThrowable cause = e.getCause();","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Debug/ProposedUtils/src/main/java/ghidra/framework/options/AutoOptionsListener.java#L139-L175","documentation":"Thrown by AutoOptionsListener.MethodOptionSetter when an @AutoOptionConsumed-annotated method declares more than two parameters. The framework only supports zero, one (new or old value), or two (old+new) parameters; a larger arity has no defined value mapping and is rejected at setter-construction time.","triggerScenarios":"An @AutoOptionConsumed method with three or more parameters, e.g. void onChange(String name, int newVal, int oldVal). Adding auxiliary parameters (a context or source) beyond the old/new pair.","commonSituations":"Refactoring a handler to take extra context arguments; copy-pasting a method signature from elsewhere without trimming to the supported arity; misunderstanding the supported parameter shapes.","solutions":["Reduce the method to 0, 1, or 2 parameters, using only old/new value slots.","Move extra context into a field on the receiver or obtain it inside the method body.","Split logic across a minimal @AutoOptionConsumed method that delegates to a helper with more args."],"exampleFix":"// before\n@AutoOptionConsumed(\"my.opt\")\nvoid onChange(PluginTool tool, int newVal, int oldVal) { ... } // 3 params\n\n// after\n@AutoOptionConsumed(\"my.opt\")\nvoid onChange(@NewValue int newVal, @OldValue int oldVal) {\n  doChange(this.tool, newVal, oldVal);\n}","handlingStrategy":"validation","validationCode":"int n = method.getParameterCount();\nif (n > 2) {\n  throw new IllegalStateException(\n    \"@AutoOptionConsumed method must have 0-2 params: \" + method);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Limit @AutoOptionConsumed methods to 0, 1, or 2 parameters.","Move extra context to receiver fields.","Run a wiring test that scans all consumed-option methods."],"tags":["ghidra","options","annotation","arity"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}