Skip to content

Suggest compilation with -parameters when AspectJAdviceParameterNameDiscoverer fails against ambiguity #34609

Closed
@xardael

Description

@xardael

Hi, I had this annotation which worked with AspectJ, however stopped working after I migrated to spring-aspects + spring-aop version 6.2.4:

@AfterReturning(pointcut = "this(processor) && @annotation(x.y.z.ProcessorListenerHook)", returning = "returnValue")
public void executeListenersAfter(JoinPoint joinPoint, Processor processor, Object returnValue) {

Exception is:

AmbiguousBindingException Binding of returning parameter is ambiguous: there are 2 candidates.

The problem is in AspectJAdviceParameterNameDiscoverer.getParameterNames - in processing parameters according to this order

public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscoverer {

  private static final String THIS_JOIN_POINT = "thisJoinPoint";
  private static final String THIS_JOIN_POINT_STATIC_PART = "thisJoinPointStaticPart";

  // Steps in the binding algorithm...
  private static final int STEP_JOIN_POINT_BINDING = 1;
  private static final int STEP_THROWING_BINDING = 2;
  private static final int STEP_ANNOTATION_BINDING = 3;
  private static final int STEP_RETURNING_BINDING = 4;
  private static final int STEP_PRIMITIVE_ARGS_BINDING = 5;
  private static final int STEP_THIS_TARGET_ARGS_BINDING = 6;
  private static final int STEP_REFERENCE_PCUT_BINDING = 7;
  private static final int STEP_FINISHED = 8;

"Returning binding" is processed BEFORE "this target binding" so during calling maybeBindReturningVariable() there are two unbound arguments left, so this method throws an exception.

  /**
   * If a returning variable was specified and there is only one choice remaining, bind it.
   */
  private void maybeBindReturningVariable() {
    if (this.numberOfRemainingUnboundArguments == 0) {
      throw new IllegalStateException(
          "Algorithm assumes that there must be at least one unbound parameter on entry to this method");
    }

    if (this.returningName != null) {
      if (this.numberOfRemainingUnboundArguments > 1) {
        throw new AmbiguousBindingException("Binding of returning parameter '" + this.returningName +
            "' is ambiguous: there are " + this.numberOfRemainingUnboundArguments + " candidates.");
      }

Is this the intended behavior?

How should I use both this and returning in one @AfterReturning annotation?

Thanks.

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)status: backportedAn issue that has been backported to maintenance branchesstatus: feedback-providedFeedback has been providedtype: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions