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


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

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

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

Back to the top