`@volatile` (https://github.com/adatao/spark/commit/b1bbbe699cd23b937e6fa5c90d5ea0fcc9801681) may help in the unlikely event that `lastSetSparkEnv` gets hotspotted; `synchronized` is overkill in this case as we're already willing to "dumb down" to whatever `lastSetSparkEnv` happens to be.

As discussed in this context, this is to hotfix-avoid highly probable NPEs given the current ThreadLocal design, without taking it away completely, in case someone still wants it. The goal isn't to provide complete guarantees on happens-before relationships at the get/set level.

A proper refactoring would have `SparkEnv.env` passed around as a parameter to most places that need it. I/we may get around to doing that, time permitting.