Skip to main content

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

How about moving:
                         if (!SwingUtilities.isEventDispatchThread()) {
                                     SwingUtilities.invokeLater(r);
                         } else {
                                     r.run();
                         }

into a standard util method, and exclude that from the pointcut ?



                                                                                                                                                                          
                      "Jim Piersol"                                                                                                                                       
                      <jrp@xxxxxxxxxxxxxxx        To:       <aspectj-users@xxxxxxxxxxx>                                                                                   
                      m>                          cc:                                                                                                                     
                      Sent by:                    Subject:  RE: Update: [aspectj-users] writing an aspect to check for Swing Thread Safety                                
                      aspectj-users-admin@                                                                                                                                
                      eclipse.org                                                                                                                                         
                                                                                                                                                                          
                                                                                                                                                                          
                      14/01/2003 14:35                                                                                                                                    
                      Please respond to                                                                                                                                   
                      aspectj-users                                                                                                                                       
                                                                                                                                                                          
                                                                                                                                                                          




Robert,

>>
>>> Your code looks fine to me, and more important, I like the idea of
>>> using aspects to check object semantics.
>>>
>>> Just one thing: do you have some unit tests that trigger your aspects
>>> to make sure they catch what they should catch?

Initially i just introduced a few coding errors to see that they were found,
but I like the idea of using a unit test for this.  We are a JUnit shop so
that would be really easy to do.

My biggest concern is that it is really difficult to find only incorrect
code.  For example, I have a Class that extends JPanel to create a fancy
status bar widget.  In that Class is a setText(String str) method.  Now
inside that method, I check to ensure I am on the EventQueue, and if not, I
use SwingUtilities.invokeLater(Runnable r) to run it.  But my aspect will
still report bad code because this method itself is called by a background
thread.  I was hoping it would realize that that method handled the Thread
safety inside of it, but it doesn't.  Here is a code snippet to further
explain:

Class StatusBar extends JPanel {
             public void setText(String message) {
                         Runnable r = new Runnable() {
                                     public void run() {
                                                 ... set some text here...
                                     }
                         };
                         if (!SwingUtilities.isEventDispatchThread()) {
                                     SwingUtilities.invokeLater(r);
                         } else {
                                     r.run();
                         }
             }
}

My Aspect will mark this a bad, even though it is protected inside...  Any
ideas are welcome.


>>>
>>> I am working on similar code myself in my free time (not much code
>>> since last November, but unfortunately not much free time, either).
>>> My code checks some basic contracts inherited from Object, like that
>>> equals should be reflexive.
>>>
>>> I also thought of writing some prosa around this like in a paper, but
>>> don't know yet whether this is too simple for explanations.
>>>
>>> Robert

_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/aspectj-users





--

This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.




Back to the top