Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] Pointcut args() matching issues / uncheckedArgument + ClassCastException

Hi all,

I'm experiencing some issues with a pointcut, and have narrowed the
problem down to a small testcase. I'm using AspectJ 1.7.3. I hope
someone could tell me if my pointcut is wrong, or if AspectJ is doing
something weird. The testcase is:

=========

import java.lang.Integer;
import java.util.*;

public class AjTest {
    public static void main(String[] args) {
        C.a(new Date(), new ArrayList<Integer>());
        C.b(new ArrayList<Integer>(), 1);
    }

    static class C {
        static void a(Date dateParam, List<Integer> listParam)
        { }

        static void b(List<Integer> listParam, int testParam)
        { }
    }

    static aspect A {
        before (List<Integer> listParam):
        execution(* C.a(.., List<Integer>)) && args(*, listParam) ||
        execution(* C.b(List<Integer>, ..)) && args(listParam, *) {

        }
    }

}

============

During compile, this gives an uncheckedArgument lint warning. During
run this _sometimes_ gives a ClassCastException (it's trying to cast
the Date to a List), but some compiles seem to work - it's really
non-deterministic. It seems like AspectJ sometimes matches the second
args() clause with the first execution() clause. Is my pointcut wrong
or unsupported, or is this a bug in AspectJ?

Output of compile and run (when it goes wrong):

===========

$ ~/aspectj1.7/bin/ajc -cp ~/aspectj1.7/lib/aspectjrt.jar -source 1.6
AjTest.java
AjTest.java:21 [warning] unchecked match of List<Integer> with List
when argument is an instance of List at join point
method-execution(void AjTest$C.a(Date, List<Integer>))
[Xlint:uncheckedArgument]
execution(* C.b(List<Integer>, ..)) && args(listParam, *) {
                                       ^^^^^^^^^
[Xlint:uncheckedArgument]
see also: AjTest.java:11::0

1 warning

===========

$ java -cp ~/aspectj1.7/lib/aspectjrt.jar:. AjTest
Exception in thread "main" java.lang.ClassCastException:
java.util.Date cannot be cast to java.util.List
at AjTest$C.a(AjTest.java:12)
at AjTest.main(AjTest.java:6)

===========

Thanks in advance for your reply.

-- 
Regards,

Mike Noordermeer
mike@xxxxxxxxx


Back to the top