Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Intercepting field access and thread-safety

Hi Andy

No problem, and yes, this is exactly what i want. I didn't know that it is possible to use an around advice with field get access. Thank you. What would be the pointcut for every field get access, regardless of the field type? I need to pass also the original value of the field, so i can change it in advice.

I think the expression would be:

get(@MyAnnotation * *.*)

but how do i pass original value?

Regards
Mirko

-----Ursprüngliche Nachricht-----
Von: aspectj-users-bounces@xxxxxxxxxxx [mailto:aspectj-users-bounces@xxxxxxxxxxx] Im Auftrag von Andy Clement
Gesendet: Freitag, 19. Oktober 2012 04:53
An: aspectj-users@xxxxxxxxxxx
Betreff: Re: [aspectj-users] Intercepting field access and thread-safety

Hi,

Sorry for the late reply, we are all at Spring One 2GX.  How about:

public class Code {
  int i = 5;
  public static void main(String[] argv) {
    new Code().foo();
  }
  public void foo() {
    System.out.println(i);
  }
}

aspect X {
  int around(): get(int Code.i) {
    return 42;
  }
}

Does that do what you want?

Andy

On 16 October 2012 12:16, Sertic Mirko, Bedag <Mirko.Sertic@xxxxxxxx> wrote:
> Hi there
>
> I'd like to know if it's possible to incercept a get field access using
> AspectJ and modify the returned value.
>
> Of course i could modify the field and set a new value using a before
> advice, but if the affected instance would be used in a multi threaded
> environment, this could lead to unwanted race conditions. So it is possible
> to intercept a field get access and return a defined value without modifying
> the original value of the field?
>
> Thanks a lot
>
> Mirko
>
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users


Back to the top