While Stephen C's and the accepted answers are good and pretty much cover it, it's worth making an important note that variable a doesn't have to be volatile - and you still won't get an NPE.
This is because there will be a happens-before relationship between a = one
and b = two
, regardless of whether a
is volatile
. So Stephen C's formal proof still applies, just no need for a
being volatile.