This is a simplified example – I have two threads:
Can JavaME and/Proguard ever reorder the obX = ... statements, such that thread_B will have a null pointer exception at ob1.someMethod?
thread_A:
Object ob1 = null;
Object ob2 = null;
...
ob1 = something1;
ob2 = something2;
thread_B:
if (ob2 != null) {
ob1.someMethod();
...
}
P.S. I do realise that synchronising these will avoid the issue. Synchronisation has both a performance overhead, and more importantly, a chance to introduce deadlock.
The current versions of ProGuard (up to version 4.8 at this time of writing) don’t reorder such statements. However, the Java memory model does allow the reordering if the fields are not volatile, so you shouldn’t rely on it. The Java virtual machine, future versions of ProGuard, or other tools may very well reorder the code. At least volatile fields won’t introduce deadlocks.