Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] writing an aspect to check for Swing Thread Safety

Jim,

Add pointcut to capture call() join point's as well. 
Since JTextField's code is not under control (assuming 
you are not weaving into JRE's rt.jar), the execution 
join points will not be adviced.

You need to still keep execution() pointcuts take care of
situations like AbstractAction, where its subclass' execution
code is under your control, but not the caller's.

pointcut restrictedExecution()
    : execution(* javax.swing+.*(..))
      || execution(javax.swing+.new())
      || call(* javax.swing+.*(..)) 
      || call(javax.swing+.new());

-Ramnivas

--- Jim Piersol <jrp@xxxxxxxxxxxxxxxx> wrote:
> Hi,
> 
> Absolute AspectJ newbie here.  Been through the docs and a few
> examples.  Now I am attempting to add a new aspect to help check for
> Swing Thread Safety.  I would like to put a pointcut on all
> executions to javax.swing code to check the
> SwingUtilities.isEventDispatchThread() method and report a message if
> the call was made outside the EventThread.  This would be used
> as a development tool to find any BAD code that could cause GUI
> anomalies, i.e. deadlocks, painting problems...
> 
> Here is what I am trying so far.  It doesn't seem to do what I want
> though.  It finds calls to things like
> javax.swing.AbstractAction but I purposely added a background Thread
> in a GUI class to instantiate and operate on a JTextField, and
> it nevers reports on it.
> 
> **************************************
> package strata.aspect;
> 
> import javax.swing.*;
> 
> public aspect TraceMyClasses {
> 
>     pointcut restrictedExecution(): execution(* javax.swing+.*(..))
>                                  || execution(javax.swing+.new());
> 
> 
>     before(): restrictedExecution() {
>         if (!SwingUtilities.isEventDispatchThread()) {
>            System.out.println("\n-->FOUND NON SAFE SWING CALL....."
>                     + "\n--> " +
> thisJoinPointStaticPart.getSignature()
>                     + "\n--> " +
> thisJoinPoint.getSourceLocation().getFileName()
>                     + "\n--> " +
> thisJoinPoint.getSourceLocation().getLine()
>                     + "\n--> " +
> thisJoinPoint.getSourceLocation().getWithinType());
>         }
>     }
> }
> 
>
****************************************************************************************************
> 
> Any help or ideas would be appreciated.  I will be sure to post any
> final results I receive from this thread.
> 
> Thanks,
> Jim
> 
>     Jim Piersol
> Senior Software Engineer
> Sun Certified Java Developer
> Strata Group, Inc.
> jrp@xxxxxxxxxxxxxxxx
> 


__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com


Back to the top