{"record":{"id":"e4fd41adff706153","repo":"mybatis/mybatis-3","slug":"method-is-not-supported-as-a-plugin-target","errorCode":null,"errorMessage":"Method '{}' is not supported as a plugin target.","messagePattern":"Method '(.+?)' is not supported as a plugin target\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/org/apache/ibatis/plugin/Invocation.java","lineNumber":41,"sourceCode":"import org.apache.ibatis.executor.Executor;\nimport org.apache.ibatis.executor.parameter.ParameterHandler;\nimport org.apache.ibatis.executor.resultset.ResultSetHandler;\nimport org.apache.ibatis.executor.statement.StatementHandler;\n\n/**\n * @author Clinton Begin\n */\npublic class Invocation {\n\n  private static final List<Class<?>> targetClasses = Arrays.asList(Executor.class, ParameterHandler.class,\n      ResultSetHandler.class, StatementHandler.class);\n  private final Object target;\n  private final Method method;\n  private final Object[] args;\n\n  public Invocation(Object target, Method method, Object[] args) {\n    if (!targetClasses.contains(method.getDeclaringClass())) {\n      throw new IllegalArgumentException(\"Method '\" + method + \"' is not supported as a plugin target.\");\n    }\n    this.target = target;\n    this.method = method;\n    this.args = args;\n  }\n\n  public Object getTarget() {\n    return target;\n  }\n\n  public Method getMethod() {\n    return method;\n  }\n\n  public Object[] getArgs() {\n    return args;\n  }\n","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/mybatis/mybatis-3/blob/008069adb1b089579b5dcba87ee591908b263274/src/main/java/org/apache/ibatis/plugin/Invocation.java#L23-L59","documentation":"Invocation's constructor rejects any method whose declaring class is not one of the four plugin target interfaces: Executor, ParameterHandler, ResultSetHandler, StatementHandler. MyBatis plugins can only intercept these interfaces, and Invocation enforces that contract at construction.","triggerScenarios":"new Invocation(target, method, args) where method.getDeclaringClass() is outside the allowed list — e.g. a method from a concrete class, Object, or another interface; typically hit by custom code wrapping the plugin API or reflecting a method resolved from an implementation class instead of the interface.","commonSituations":"Custom interceptors or frameworks building Invocation manually; obtaining the Method via target.getClass().getMethod(...) instead of Executor.class.getMethod(...); JDK default methods whose declaring class differs from the target interface.","solutions":["Resolve the Method from the target interface: Executor.class.getMethod(\"query\", ...), not from the implementing class.","Only intercept methods declared on Executor, ParameterHandler, ResultSetHandler, or StatementHandler.","If you need to intercept something else, use a different mechanism (e.g. decorator around the SqlSessionFactory), not the plugin Invocation API."],"exampleFix":"// before\nMethod m = target.getClass().getMethod(\"query\", MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class);\nnew Invocation(target, m, args);\n// after\nMethod m = Executor.class.getMethod(\"query\", MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class, CacheKey.class, BoundSql.class);\nnew Invocation(target, m, args);","handlingStrategy":"validation","validationCode":"private static final List<Class<?>> TARGETS = Arrays.asList(Executor.class, ParameterHandler.class, ResultSetHandler.class, StatementHandler.class);\nif (!TARGETS.contains(method.getDeclaringClass())) throw new IllegalArgumentException(\"not a plugin target\");","typeGuard":"boolean isPluginTarget(Method m) {\n  return m != null && TARGETS.contains(m.getDeclaringClass());\n}","tryCatchPattern":null,"preventionTips":["Always resolve intercepted Methods from the four target interfaces, never from implementation classes.","Treat the plugin API as closed: anything outside Executor/ParameterHandler/ResultSetHandler/StatementHandler needs a decorator, not a plugin."],"tags":["mybatis","plugin","interceptor","reflection"],"backgroundTag":null,"analyzedSha":"008069adb1b089579b5dcba87ee591908b263274","analyzedAt":"2026-08-14T13:07:10.264Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}