开发者

Array element set pointcut. Is there a workaround?

开发者 https://www.devze.com 2023-01-23 05:52 出处:网络
I just read that it is not possible to define a pointcut on a single array element (bug link). Considering I really need to detect an array element modification, I would like to know if there is any w

I just read that it is not possible to define a pointcut on a single array element (bug link). Considering I really need to detect an array element modification, I would like to know if there is any workaround for this kind of problem (a pattern or something).

Something like what is described in this article

public class FieldPointcuts {
     static int ar[];

     public static void main(String[] args) {
         ar = new int[] {100}; //set
         ar[0] = 200; //get
     }
}

and advice

before(int i, Object s, Object[] a):
    arrayset() && args(i, s) && target(a)
{
    Syst开发者_运维技巧em.out.println (" Arrayset:["+i+"/"+(a.length-1)+"] = "+s) ;
}

Thanks in advance.


Unfortunately, there is nothing I can think of that will work. The best that I can think of would be to use Lists instead of arrays, but if you are weaving into third party code, this would not be possible.

0

精彩评论

暂无评论...
验证码 换一张
取 消