Skip to content

Nullable CallbackInfo optimization does not properly consider static handlers in instance target methods #178

@cputnam-a11y

Description

@cputnam-a11y

A null callback info is passed to static handlers that target instance methods and capture the enclosing method args regardless of whether the handler uses the callback info. this happens because the calculation of callbackInfoSlot in CallbackInjector$Callback doesn't consider the handler being static unless the handler doesn't capture the enclosing method arguments.

public class CallbackInjector extends Injector {
  // ...
  private class Callback extends InsnList {
    // ...
    Callback(MethodNode handler, Target target, final InjectionNode node, final LocalVariableNode[] locals, boolean captureLocals) {
      // ...
      int callbackInfoSlot = handlerArgs.length == 1 ? Bytecode.isStatic(handler) ? 0 : 1 : frameSize;
      // ...
    }
  }
}

it seems to me that this could be fixed like so:

- int callbackInfoSlot = handlerArgs.length == 1 ? Bytecode.isStatic(handler) ? 0 : 1 : frameSize;
+ int callbackInfoSlot = handlerArgs.length == 1 ? Bytecode.isStatic(handler) ? 0 : 1 : Bytecode.isStatic(handler) && !target.isStatic ? (frameSize - 1) : frameSize;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions