Skip to main content

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

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(;

    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.
    Jim Piersol
Senior Software Engineer
Sun Certified Java Developer
Strata Group, Inc.

Back to the top