Skip to main content

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

I previously posted to ask advice on creating an Aspect that would help
check for Swing Thread Safety issues.  After a little help, I have an Aspect
that will sortof do the job.  The biggest hurdle is trying to decide when a
call is safe or not.  I choose for the time being, to restrict the checking
to set* and add* calls in javax.swing code.  Here is my Aspect.  I would
appreciate info from anyone who knows how to improve it or enhance it.

package strata.aspect;

import javax.swing.*;

public aspect FindBadSwingCode {

    pointcut executingAnySwing(): execution(* javax.swing..*+.*(..))
                                  || execution(;

    pointcut callingAnySwing(): call(* javax.swing+.*(..))
                                || call(;

    pointcut isItASetOrAddCall(): execution(* javax.swing..*+.set*(..))
                                  || call(* javax.swing+.set*(..))
                                  || execution(* javax.swing..*+.add*(..))
                                  || call(* javax.swing+.add*(..));

    pointcut mustBeAComponent(): target(java.awt.Component);

    pointcut catchBadSwingCode(): (executingAnySwing()
                                  || callingAnySwing())
                                  && mustBeAComponent()
                                  && isItASetOrAddCall();

    before(): catchBadSwingCode() {
        if (((java.awt.Component)thisJoinPoint.getTarget()).isShowing()) {
            if (!SwingUtilities.isEventDispatchThread()) {
               System.out.println("\n\n-->Possible Non-Safe Swing Call....."
                + "\n--> " + thisJoinPointStaticPart.getSignature()
                + "\n--> " + thisJoinPoint.getSourceLocation().getLine());


Back to the top