Thanks Andy.

Indeed - separate pointcuts is exactly what I ended up doing; it just makes
the code feel a little more cluttered.

A bug has been raised here:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=509235

Thanks,

Eric


On Tue, Dec 13, 2016 at 5:36 PM, Andy Clement <[email protected]>
wrote:

> Hi Eric,
>
> I was half surprised you didn't get a compiler warning/error that it
> didn't like your alternatives for binding - to be clear, there is nothing
> wrong with them theoretically, but I thought the compiler would say it
> doesn't support doing that. But I just crafted a small similar program and
> it does what you describe. So definitely an issue - it should either work
> or you get told it isn't supported. But it shouldn't silently do the wrong
> thing.  My test program:
>
> ---
> public class Code {
>   public static void main(String []argv) {
>     foo("fooname",1,2,3);
>     bar("barone","bartwo","barname",1,2,3);
>   }
>
>   public static void foo(String username, int i, int j, int k) {}
>
>   public static void bar(String a, String b, String username, int i, int
> j, int k) { }
> }
>
> aspect X {
>   before(String username): (execution(public static * foo(..)) &&
> args(username,..)) ||
>                            (execution(public static * bar(..)) &&
> args(*,*,username,..)) {
>     System.out.println("username = "+username);
>   }
> }
> ---
>
> prints
>
> username = fooname
> username = barone
>
> Please raise an issue on: https://bugs.eclipse.org/
> bugs/enter_bug.cgi?product=AspectJ
>
> I'm suspecting the pointcut validation and rewriting that goes on. I'm
> sure you know what the workaround is. Just have two pieces of advice with
> different pointcuts attached.
>
> Andy
>
>
> On 13 December 2016 at 13:02, Eric B <[email protected]> wrote:
>
>> A few more tests and, not surprisingly, I got no further:
>> @Pointcut("execution(public static * business.security.service.Logi
>> nManagerHelper.authenticateUser(..)) && args( username, ..)")
>> public void authenticateUser(String username){}
>>
>> @Pointcut("execution(public static * 
>> webapp.util.LoginManagerAction.loginJAAS(..))
>> && args( *, *, username, ..)" )
>> public void loginJAAS(String username) {}
>> @Before("authenticateUser(username) || loginJAAS(username)" )
>> public void setUsername(JoinPoint jp, String username) {
>> // inject the username into the MDC
>> MDCUtils.setUsername(username);
>> }
>>
>>
>> Not surprisingly, this produces the exact same results.
>>
>> Is this a bug, or just me doing this incorrectly?
>>
>> Thanks,
>> Eric
>>
>>
>> On Tue, Dec 13, 2016 at 3:25 PM, Eric B <[email protected]> wrote:
>>
>>> Hi,
>>>
>>> I just posted this on StackOverflow, but then realized I might have
>>> better success asking a specific question like this here:
>>>
>>> I've got an pointcut that I am trying to use with LTW.  I have 2 methods
>>> that I am trying to advise, each with a different parameter list.  However,
>>> they both have a single common parameter that I want.
>>>
>>> These are the method signatures I want to advise:
>>>
>>>        public static WorkflowModifierFlags authenticateUser(String
>>> username, String password, String ip, boolean webGUI, boolean
>>> realAuthentication)
>>>
>>>        public static boolean loginJAAS(HttpServletRequest request,
>>> HttpServletResponse response, String username, String password, HttpSession
>>> session)
>>>
>>>
>>> I've tried the following pointcut/advice, but it is failing; the
>>> username variable is sometimes getting injected with the IP address (ie:
>>> the args() from the first pointcut).
>>>
>>>     @Before("(execution(public static * business.security.service.Logi
>>> nManagerHelper.authenticateUser(..)) && args( username, ..)) || "
>>>     + "(execution(public static * 
>>> webapp.util.LoginManagerAction.loginJAAS(..))
>>> && args( *, *, username, ..))" )
>>>     public void setUsername(JoinPoint jp, String username) {
>>>     // inject the username into the MDC
>>>     MDCUtils.setUsername(username);
>>>     }
>>>
>>>
>>> I would have expected that the `args()` parameter is associated to the
>>> execution() method, but sometimes it would appear that it is "confused",
>>> and gives me the IP instead of the username.
>>>
>>> Am I using AspectJ incorrectly, or is this a bug in the LTW?  I'm
>>> running AspectJ 1.6.13.
>>>
>>> Thanks,
>>>
>>> Eric
>>>
>>>
>>
>> _______________________________________________
>> aspectj-users mailing list
>> [email protected]
>> To change your delivery options, retrieve your password, or unsubscribe
>> from this list, visit
>> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>>
>
>
> _______________________________________________
> aspectj-users mailing list
> [email protected]
> To change your delivery options, retrieve your password, or unsubscribe
> from this list, visit
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
_______________________________________________
aspectj-users mailing list
[email protected]
To change your delivery options, retrieve your password, or unsubscribe from 
this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-users

Reply via email to