Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AspectJ unmatched type warning: how to interpret?

My goal is to 'around' all the equals methods of the subclasses of a type. So, I wrote the following aspect.

I'm using the aspectj-maven-plugin, and I'm telling it to weave the code in a dependency jar file, since that's where all the equals methods are.

I am rewarded with:

Warning:(22, 0) ajc: does not match because declaring type is java.lang.Object, if match desired use target(com.basistech.rosette.dm.BaseAttribute+) [Xlint:unmatchedSuperTypeInCall] 
Warning:(22, 0) ajc: advice defined in com.basistech.rosette.dm.AdmEquals has not been applied [Xlint:adviceDidNotMatch]

I am puzzled. Plenty of types in the hierarchy of BaseAttribute declare equals, so it should not be looking at Object. Adding &&target(BaseAttribute+) does not seem to make this error go away.

What am I missing, and/or how should I go about tracking this down?

package com.basistech.rosette.dm;

/**
 * See if we can't make an aspect to spy on equals ...
 */
public aspect AdmEquals {
    // we would like to narrow this to subclasses ...
    boolean around(Object other): call(public boolean BaseAttribute+.equals(java.lang.Object)) && args(other) {
        boolean result = proceed(other);
        if (!result) {
            System.out.println(this);
            System.out.println(other);
            System.out.println(result);
        }
        return true;
    }
}
like image 543
bmargulies Avatar asked Nov 24 '25 15:11

bmargulies


1 Answers

OK, light dawned. The AspectJ call specs describe where a method is defined at the base of the class hierarchy, apparently, not where it is overridden. So the following purports to do the necessary dirty work.

public aspect AdmEquals {
    // we would like to narrow this to subclasses ...
    boolean around(Object other) : 
        call(public boolean Object.equals(java.lang.Object)) &&
        args(other) &&
        target(BaseAttribute+)
    {
        boolean result = proceed(other);
        if (!result) {
            System.out.println(this);
            System.out.println(other);
            System.out.println(result);
        }
        return true;
    }
}
like image 64
bmargulies Avatar answered Nov 27 '25 05:11

bmargulies



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!