And the solution seems to be:
Object around() : get(@Annotation * *.*) {
try {
Object theReturnValue = proceed();
// Do something here
return theReturnValue;
} catch (Throwable e) {
throw new RuntimeException("Something went wrong", e);
}
}
Greets
Mirko
-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Sertic Mirko, Bedag
Gesendet: Freitag, 19. Oktober 2012 13:13
An: [email protected]
Betreff: Re: [aspectj-users] Intercepting field access and thread-safety
Hi there again
This pointcut sounds right, but the aspect is not applied at all.
around() : get(@Annotation * *.*) -> Matches everything correctly, but no
return value bound
around(Object val) : get(@Annotation * *.*) && args(val) -> Matches nothing
I tried to fiddle with the proceedingJoinPoint.proceed() to get the field
access return value, but this always returns null.
Any ideas?
Regards
Mirko
-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Sertic Mirko, Bedag
Gesendet: Freitag, 19. Oktober 2012 08:53
An: [email protected]
Betreff: Re: [aspectj-users] Intercepting field access and thread-safety
argg, yes, of course, you are right.
Regards
Mirko
-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Romain MULLER
Gesendet: Freitag, 19. Oktober 2012 08:14
An: [email protected]
Betreff: Re: [aspectj-users] Intercepting field access and thread-safety
You'll want to use:
around(Object val) : get(@Annotation * *.*) && args(val) {...}
_________________________
Sent over RFC-1149 compliant transport - please excuse occasionnal packet loss
Le 19 oct. 2012 à 08:09, "Sertic Mirko, Bedag" <[email protected]> a écrit :
> 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: [email protected]
> [mailto:[email protected]] Im Auftrag von Andy Clement
> Gesendet: Freitag, 19. Oktober 2012 04:53
> An: [email protected]
> 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 <[email protected]> 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
>> [email protected]
>> https://dev.eclipse.org/mailman/listinfo/aspectj-users
> _______________________________________________
> aspectj-users mailing list
> [email protected]
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
> _______________________________________________
> aspectj-users mailing list
> [email protected]
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
_______________________________________________
aspectj-users mailing list
[email protected]
https://dev.eclipse.org/mailman/listinfo/aspectj-users
_______________________________________________
aspectj-users mailing list
[email protected]
https://dev.eclipse.org/mailman/listinfo/aspectj-users
_______________________________________________
aspectj-users mailing list
[email protected]
https://dev.eclipse.org/mailman/listinfo/aspectj-users