AspectJ: Advice not working for array type

Viewed 68

I defined a pointcut based on a type that's not available when I compile my aspect, but is available when I compile my code.
It works fine when I use a simple type, but not when I use an array.

It looks like the type is being flattened and treated as a non-array type (not being applied for the array type and being applied for the non-array type, exactly the opposite of expected).

Simple reproduction

Aspect:

public aspect Aspect {
    after() : call(public MaybeMissingClass MaybeMissingClass.*())
    {
        System.out.println("Aspect: MaybeMissingClass 1");
    }
    after() : call(public MaybeMissingClass[] MaybeMissingClass.*())
    {
        System.out.println("Aspect: MaybeMissingClass[] 2");
    }
}

Class:

// compile all together
//      java -cp aspectjtools.jar;aspectjrt.jar org.aspectj.tools.ajc.Main -source 1.6 Aspect.aj Main.java
// compile aspect without concrete class in CP and then compile class
//      java -cp aspectjtools.jar;aspectjrt.jar org.aspectj.tools.ajc.Main -source 1.6 Aspect.aj
//      java -cp aspectjtools.jar;aspectjrt.jar org.aspectj.tools.ajc.Main -source 1.6 -aspectpath . Main.java

// run
//      java -cp .;aspectjtools.jar;aspectjrt.jar Main

import java.io.*;
import java.util.*;

public class Main {
    
    public static void main(String[] args) throws Exception {
        System.out.println("hello from main");
        MaybeMissingClass.f1();
        MaybeMissingClass.f2();
    }
}

class MaybeMissingClass {
    public static MaybeMissingClass f1(){System.out.println("hello from MaybeMissingClass.f1");return null;}
    public static MaybeMissingClass[] f2(){System.out.println("hello from MaybeMissingClass.f2");return null;}
}

Output when compiling all together:

hello from main
hello from MaybeMissingClass.f1
Aspect: MaybeMissingClass 1
hello from MaybeMissingClass.f2
Aspect: MaybeMissingClass[] 2

Output when compiling aspect separately:

hello from main
hello from MaybeMissingClass.f1
Aspect: MaybeMissingClass 1
Aspect: MaybeMissingClass[] 2
hello from MaybeMissingClass.f2

Can anyone explain this?

Edit
Looks like the dimension info is getting lost when calling resolveBindingsForMissingType() instead of resolveBindingsForExactType().
But it doesn't really make sense. This info is available at aspect-compile-time and at weave-time, so why discard it?

0 Answers
Related