0

I am working on a Swing application which uses SwingWorker to perform logic in the background. I tried to write an aspect to remove the error handling from class A(and several others) and centralize it using aspectJ. So far I wasn't able to write a pointcut to catch doInBackground and propertyChange methods.

@Component
public class A{

    public void perform(final String val) {
        final SwingWorker<String, Object> myWorker = new SwingWorker<String, Object>(){

            @Override
            protected String doInBackground() throws Exception {
                String response = null;
                try{
                    //do logic and return response  
                }catch(MyException e){
                    response "myexception";
                }catch(MyException2 e){
                    response "myexception2";
                }catch(Exception e){
                    response = "fatal exception"
                }
                return response;
            }
        };

        myWorker.addPropertyChangeListener(new PropertyChangeListener() {
            @Override   
            public void propertyChange(PropertyChangeEvent evt) {
              try {
                    //do logic
              }catch(MyException3 e){
                    //do logic
              }catch(Exception e){
                    //do logic
              }
            }
        });
        myWorker.execute();
    }
}
Brad Larson
  • 170,088
  • 45
  • 397
  • 571
user3278795
  • 11
  • 1
  • 2

1 Answers1

0

check out this answer.

@AspectJ pointcut for subclasses of a class with an annotation

aspects are woven into the bytecode of a class, it doesnt matter which thread that bytecode is running on. also anonymous classes still generate the same bytecode as regular classes, but they just dont have names. so neither of these issue should affect you.

what most likely is causing the problem is that your writing a pointcut to match on a specific method invocation SwingWorker.doInBackground. what you need is a pointcut to match on the invocation of any subtype of SwingWorker SwingWorker+.doInBackground

Community
  • 1
  • 1
aepurniet
  • 1,719
  • 16
  • 24
  • Thanks for the hint @aepurniet . I tried your suggestion but it's still not working. I found as well this example http://stackoverflow.com/questions/1366360/aspectj-inner-class-join-points. – user3278795 Apr 07 '14 at 08:37