[ Content | View menu ]

Java synchronisation bug on OS/X?

Written on 18 Mar 2009

I’ve come across what might be a synchronisation bug while working on the book.

The end-to-end tests for our example application use the WindowLicker framework to drive the Swing user interface. Our test infrastructure starts the application up in another thread (it’s as close as we can get to running from the command line), then creates a WindowLicker driver which, eventually, creates a Java AWT Robot. It turns out (we think) that this means that we have two threads trying to load and initialise the AWT library in parallel, which hangs. Our workaround is to call a delaying method before creating the WindowLicker Driver:

private void 
makeSureAwtIsLoadedBeforeStartingTheDriverOnOSXToStopDeadlock() {
  try {
    SwingUtilities.invokeAndWait(
      new Runnable() { public void run() {} });
  } catch (Exception e) {
    throw new Defect(e);
  }
}

That’s not really what invokeAndWait() is for, but it solves our problem until we can find a better answer, and we hope that the hack is at least self-explanatory.

Does anyone have a better explanation or fix? OS/X 10.5.6, Java 1.5.0_16, White MacBook 2.4 GHz Intel Core Duo. Nat’s Linux installation works fine.

Filed in: Coding, Test-Driven.

2 Comments

Write comment - TrackBack - RSS Comments

  1. Comment by Channing Walton:

    Does windowlicker do anything native? If so, your problem might be similar to the one eclipse had to deal with, see http://developer.apple.com/technotes/tn2005/tn2147.html#TNTAG31

    19 Mar 2009 @ 22:00
  2. Comment by steve.freeman:

    @Channing. Not that we’re aware of. It’s all pukka Java.

    20 Mar 2009 @ 11:17
Write comment