Hi all,

I have been chasing down a problem in a MIDP application when using Display.callSerially. The application works fine on the 6650 emulator but was misbehaving on the 7210 emulator. I have traced the problem to what I believe is a bug in the 7210 emulator's implementation of Display.callSerially. I am posting here for the information of others that may have trouble and to hopefully get a response from the nokia engineers.

According to the MIDP javadoc, "The run() method will be called exactly once for each call to callSerially(). Calls to run() will occur in the order in which they were requested by calls to callSerially()." On the 7210 emulator, the Runnables seemed to occasionally run out of order. In desperation, I decompiled the emulator class files to try to understand what was happening.

The callSerially method was implemented like this:

private static Vector s_callSeriallyQueue = new Vector();

public void callSerially(Runnable r)
{
if(this == s_display)
{
if(r == null)
throw new NullPointerException();
s_callSeriallyQueue.addElement(r);
JavaEventGenerator.s_generateEvent(0, 2, 3, 0);
}
}

ie. the new Runnable as appended to a Vector pending execution. As far as I can gather, s_generateEvent schedules a "display event" on the appropriate display thread. So far so good. However, sometime later the following is executed:

final void consumeDisplayEvent(int type)
{
switch(type)
{

// ---8<--- snip!

case 3: // '\003'
if(s_callSeriallyQueue.size() > 0)
{
Runnable r = (Runnable)s_callSeriallyQueue.elementAt(
s_callSeriallyQueue.size() - 1);
r.run();
s_callSeriallyQueue.removeElementAt(
s_callSeriallyQueue.size() - 1);
} else
{
throw new RuntimeException(
"Display ERROR: Unknown event type " + type);
}
break;

// ---8<--- snip!

}
}

It appears that the Runnables are consumed from the end of the vector rather than the beginning. Thus, if there are more than one Runnables added before this method executes, the Runnables will be executed in *reverse* order, clearly violating the guarantees of callSerially cited above. The code used by the 6650 emulator appears to be much more sensible.

Has anyone else experienced this apparent bug? Is there an update planned to fix this?

Thanks, Trent.