[HOTFIX] Extend thread safety for SparkEnv.get()
[HOTFIX] Extend thread safety for SparkEnv.get()

A ThreadLocal SparkEnv.env is facing various situations leading to
NullPointerExceptions, where SparkEnv.env set in one thread is not
gettable in another thread, but often assumed to be available.

See, e.g., https://groups.google.com/forum/#!topic/spark-developers/GLx8yunSj0A

This hotfixes SparkEnv.env to return either (a) the ThreadLocal
value if non-null, or (b) the previously set value in any thread.

This approach preserves SparkEnv.set() thread safety needed by
RDD.compute() and possibly other places. A refactoring that
parameterizes SparkEnv should be addressed subsequently.

On branch adatao-global-SparkEnv
Changes to be committed:

	modified:   core/src/main/scala/spark/SparkEnv.scala

witgo/spark,mdespriee/spark,huang1900/spark,wzhfy/spark,jlopezmalla/spark,shuangshuangwang/spark,actuaryzhang/spark,WeichenXu123/spark,cloud-fan/spark,cin/spark,eyalfa/spark,huang1900/spark,WindCanDie/spark,holdenk/spark,jkbradley/spark,wangmiao1981/spark,minixalpha/spark,ddna1021/spark,patrick-nicholson/spark,debugger87/spark,JerryLead/spark,markhamstra/spark,nilsgrabbert/spark,highfei2011/spark,witgo/spark,lxsmnv/spark,cloud-fan/spark,dhruve/spark,haowu80s/spark,liutang123/spark,jiangxb1987/spark,chuckchen/spark,goldmedal/spark,ioana-delaney/spark,ericvandenbergfb/spark,loneknightpy/spark,JerryLead/spark,saltstar/spark,Aegeaner/spark,pronix/spark,setjet/spark,WeichenXu123/spark,caneGuy/spark,debugger87/spark,jianran/spark,highfei2011/spark,mzl9039/spark,ericvandenbergfb/spark,holdenk/spark,minixalpha/spark,andrewor14/spark,JoshRosen/spark,ericvandenbergfb/spark,sahilTakiar/spark,byakuinss/spark,rezasafi/spark,HyukjinKwon/spark,BryanCutler/spark,rekhajoshm/spark,sureshthalamati/spark,yanboliang/spark,debugger87/spark,jkbradley/spark,saturday-shi/spark,apache/spark,setjet/spark,loneknightpy/spark,huang1900/spark,mzl9039/spark,mahak/spark,spark-test/spark,apache-spark-on-k8s/spark,szhem/spark,mkolod/incubator-spark,ericvandenbergfb/spark,JoshRosen/spark,lvdongr/spark,UndeadBaneGitHub/spark,facaiy/spark,SnappyDataInc/spark,apache/spark,zero323/spark,stanzhai/spark,MLnick/spark,michalsenkyr/spark,rekhajoshm/spark,akopich/spark,actuaryzhang/spark,setjet/spark,mdespriee/spark,sureshthalamati/spark,jianran/spark,kimoonkim/spark,liutang123/spark,skonto/spark,dotunolafunmiloye/spark,szhem/spark,vinodkc/spark,mzl9039/spark,WindCanDie/spark,panfengfeng/spark,huang1900/spark,Aegeaner/spark,ueshin/apache-spark,bdrillard/spark,gengliangwang/spark,nlalevee/spark,wangmiao1981/spark,xflin/spark,byakuinss/spark,BryanCutler/spark,liutang123/spark,zuotingbing/spark,ptkool/spark,yanboliang/spark,BryanCutler/spark,panfengfeng/spark,wzhfy/spark,big-pegasus/spark,srowen/spark,kevinyu98/spark,publicRoman/spark,aosagie/spark,saltstar/spark,saturday-shi/spark,holdenk/spark,lxsmnv/spark,ueshin/apache-spark,janewangfb/spark,narahari92/spark,mike0sv/spark,chuckchen/spark,nchammas/spark,taroplus/spark,rednaxelafx/apache-spark,vinodkc/spark,bOOm-X/spark,sahilTakiar/spark,ibm-research-ireland/sparkoscope,saltstar/spark,sahilTakiar/spark,stanzhai/spark,panfengfeng/spark,xflin/spark,caneGuy/spark,sachintyagi22/spark,gengliangwang/spark,andrewor14/spark,spark-test/spark,sachintyagi22/spark,apache-spark-on-k8s/spark,chuckchen/spark,michalsenkyr/spark,szhem/spark,HyukjinKwon/spark,taroplus/spark,ptkool/spark,apache-spark-on-k8s/spark,shuangshuangwang/spark,jrshust/spark,ahnqirage/spark,big-pegasus/spark,apache/spark,dbtsai/spark,taroplus/spark,dongjoon-hyun/spark,ahnqirage/spark,sachintyagi22/spark,actuaryzhang/spark,1haodian/spark,ConeyLiu/spark,alunarbeach/spark,JerryLead/spark,ioana-delaney/spark,ddna1021/spark,xflin/spark,esi-mineset/spark,ptkool/spark,someorz/spark,saturday-shi/spark,tejasapatil/spark,milliman/spark,kissmetrics/spark,shaneknapp/spark,jianran/spark,tejasapatil/spark,mike0sv/spark,icexelloss/spark,dhruve/spark,wzhfy/spark,metamx/spark,tejasapatil/spark,joseph-torres/spark,highfei2011/spark,shuangshuangwang/spark,milliman/spark,cloud-fan/spark,ddna1021/spark,mdespriee/spark,lvdongr/spark,haowu80s/spark,hvanhovell/spark,gengliangwang/spark,rekhajoshm/spark,aokolnychyi/spark,brad-kaiser/spark,dbtsai/spark,rezasafi/spark,kissmetrics/spark,liyichao/spark,nilsgrabbert/spark,jrshust/spark,eyalfa/spark,debugger87/spark,wzhfy/spark,jlopezmalla/spark,icexelloss/spark,shubhamchopra/spark,kiszk/spark,cloudera/spark,someorz/spark,goldmedal/spark,gengliangwang/spark,rednaxelafx/apache-spark,liutang123/spark,JoshRosen/spark,milliman/spark,icexelloss/spark,poffuomo/spark,facaiy/spark,witgo/spark,zuotingbing/spark,xuanyuanking/spark,zero323/spark,jianran/spark,jkbradley/spark,patrick-nicholson/spark,WindCanDie/spark,someorz/spark,BryanCutler/spark,WeichenXu123/spark,darionyaphet/spark,haowu80s/spark,zuotingbing/spark,Panos-Bletsos/spark-cost-model-optimizer,holdenk/spark,UndeadBaneGitHub/spark,cloudera/spark,kissmetrics/spark,SnappyDataInc/spark,dbtsai/spark,cin/spark,lvdongr/spark,bOOm-X/spark,skonto/spark,hhbyyh/spark,jlopezmalla/spark,joseph-torres/spark,jiangxb1987/spark,eyalfa/spark,nchammas/spark,sureshthalamati/spark,highfei2011/spark,zhouyejoe/spark,kevinyu98/spark,ron8hu/spark,michalsenkyr/spark,apache-spark-on-k8s/spark,rikima/spark,dhruve/spark,ron8hu/spark,rednaxelafx/apache-spark,wangyum/spark,caneGuy/spark,esi-mineset/spark,SHASHANKB/spark,rekhajoshm/spark,dotunolafunmiloye/spark,poffuomo/spark,saltstar/spark,apache/spark,narahari92/spark,SnappyDataInc/spark,andrewor14/spark,liyichao/spark,pronix/spark,zhouyejoe/spark,shubhamchopra/spark,BryanCutler/spark,caneGuy/spark,ron8hu/spark,liyichao/spark,metamx/spark,nlalevee/spark,actuaryzhang/spark,markhamstra/spark,ptkool/spark,mahak/spark,jianran/spark,gengliangwang/spark,andrewor14/iolap,rezasafi/spark,ptkool/spark,jianran/spark,dhruve/spark,icexelloss/spark,hvanhovell/spark,minixalpha/spark,setjet/spark,markhamstra/spark,sryza/spark,1haodian/spark,map222/spark,ahnqirage/spark,rekhajoshm/spark,Aegeaner/spark,poffuomo/spark,mzl9039/spark,liyichao/spark,pronix/spark,nchammas/spark,rezasafi/spark,tengpeng/spark,ajaysaini725/spark,gengliangwang/spark,xuanyuanking/spark,kissmetrics/spark,tengpeng/spark,huang1900/spark,SHASHANKB/spark,xflin/spark,JerryLead/spark,joseph-torres/spark,mdespriee/spark,dhruve/spark,metamx/spark,rikima/spark,bravo-zhang/spark,maropu/spark,sachintyagi22/spark,byakuinss/spark,mahak/spark,brad-kaiser/spark,brad-kaiser/spark,jkbradley/spark,ueshin/apache-spark,ConeyLiu/spark,goldmedal/spark,apache/spark,dbtsai/spark,haowu80s/spark,shaneknapp/spark,loneknightpy/spark,SHASHANKB/spark,zero323/spark,goldmedal/spark,nilsgrabbert/spark,actuaryzhang/spark,saltstar/spark,sryza/spark,xflin/spark,cloud-fan/spark,panfengfeng/spark,taroplus/spark,mzl9039/spark,andrewor14/iolap,loneknightpy/spark,pgandhi999/spark,SHASHANKB/spark,hhbyyh/spark,zero323/spark,ibm-research-ireland/sparkoscope,metamx/spark,andrewor14/iolap,hhbyyh/spark,ueshin/apache-spark,vinodkc/spark,brad-kaiser/spark,caneGuy/spark,eyalfa/spark,kevinyu98/spark,zzcclp/spark,nlalevee/spark,pgandhi999/spark,akopich/spark,srowen/spark,SnappyDataInc/spark,jlopezmalla/spark,ericvandenbergfb/spark,map222/spark,WeichenXu123/spark,techaddict/spark,sahilTakiar/spark,mike0sv/spark,setjet/spark,bOOm-X/spark,LantaoJin/spark,WeichenXu123/spark,lvdongr/spark,andrewor14/iolap,Panos-Bletsos/spark-cost-model-optimizer,MLnick/spark,narahari92/spark,bravo-zhang/spark,JoshRosen/spark,publicRoman/spark,panfengfeng/spark,techaddict/spark,holdenk/spark,shaneknapp/spark,szhem/spark,bOOm-X/spark,lxsmnv/spark,chuckchen/spark,holdenk/spark,skonto/spark,srowen/spark,lxsmnv/spark,WindCanDie/spark,jlopezmalla/spark,MLnick/spark,maropu/spark,nilsgrabbert/spark,loneknightpy/spark,ron8hu/spark,mkolod/incubator-spark,hvanhovell/spark,shubhamchopra/spark,big-pegasus/spark,darionyaphet/spark,kiszk/spark,LantaoJin/spark,1haodian/spark,wangyum/spark,tejasapatil/spark,zhouyejoe/spark,adrian-ionescu/apache-spark,ConeyLiu/spark,xuanyuanking/spark,szhem/spark,UndeadBaneGitHub/spark,facaiy/spark,tengpeng/spark,jrshust/spark,caneGuy/spark,jiangxb1987/spark,zuotingbing/spark,wangmiao1981/spark,wangmiao1981/spark,aosagie/spark,zuotingbing/spark,big-pegasus/spark,lvdongr/spark,mkolod/incubator-spark,map222/spark,adrian-ionescu/apache-spark,sahilTakiar/spark,dongjoon-hyun/spark,jrshust/spark,HyukjinKwon/spark,HyukjinKwon/spark,mahak/spark,liutang123/spark,esi-mineset/spark,patrick-nicholson/spark,aray/spark,JerryLead/spark,liutang123/spark,sureshthalamati/spark,dotunolafunmiloye/spark,ajaysaini725/spark,MLnick/spark,poffuomo/spark,cin/spark,saltstar/spark,joseph-torres/spark,Aegeaner/spark,dhruve/spark,kevinyu98/spark,cloudera/spark,stanzhai/spark,rekhajoshm/spark,MLnick/spark,ConeyLiu/spark,byakuinss/spark,esi-mineset/spark,BryanCutler/spark,loneknightpy/spark,aray/spark,esi-mineset/spark,pgandhi999/spark,kiszk/spark,alunarbeach/spark,andrewor14/spark,map222/spark,someorz/spark,skonto/spark,MLnick/spark,techaddict/spark,Aegeaner/spark,jrshust/spark,hvanhovell/spark,darionyaphet/spark,srowen/spark,shuangshuangwang/spark,hhbyyh/spark,janewangfb/spark,publicRoman/spark,akopich/spark,Panos-Bletsos/spark-cost-model-optimizer,LantaoJin/spark,rikima/spark,tengpeng/spark,alunarbeach/spark,maropu/spark,nilsgrabbert/spark,matthewfranglen/spark,JoshRosen/spark,icexelloss/spark,panfengfeng/spark,dongjoon-hyun/spark,zhouyejoe/spark,nchammas/spark,zero323/spark,kissmetrics/spark,debugger87/spark,esi-mineset/spark,aray/spark,vinodkc/spark,guoxiaolongzte/spark,saturday-shi/spark,aray/spark,rednaxelafx/apache-spark,kiszk/spark,alunarbeach/spark,Panos-Bletsos/spark-cost-model-optimizer,facaiy/spark,map222/spark,ueshin/apache-spark,WindCanDie/spark,jlopezmalla/spark,dotunolafunmiloye/spark,metamx/spark,cloud-fan/spark,LantaoJin/spark,publicRoman/spark,andrewor14/spark,rekhajoshm/spark,kissmetrics/spark,narahari92/spark,witgo/spark,mike0sv/spark,hvanhovell/spark,aosagie/spark,pgandhi999/spark,akopich/spark,sachintyagi22/spark,aokolnychyi/spark,hhbyyh/spark,eyalfa/spark,caneGuy/spark,someorz/spark,Panos-Bletsos/spark-cost-model-optimizer,dbtsai/spark,narahari92/spark,sryza/spark,poffuomo/spark,zuotingbing/spark,zzcclp/spark,alunarbeach/spark,chuckchen/spark,kimoonkim/spark,szhem/spark,techaddict/spark,ibm-research-ireland/sparkoscope,markhamstra/spark,dbtsai/spark,1haodian/spark,BryanCutler/spark,kissmetrics/spark,bOOm-X/spark,mike0sv/spark,tengpeng/spark,janewangfb/spark,dongjoon-hyun/spark,ConeyLiu/spark,jiangxb1987/spark,shubhamchopra/spark,pgandhi999/spark,ibm-research-ireland/sparkoscope,kimoonkim/spark,gioenn/xSpark,markhamstra/spark,darionyaphet/spark,taroplus/spark,alunarbeach/spark,icexelloss/spark,apache-spark-on-k8s/spark,icexelloss/spark,janewangfb/spark,aosagie/spark,guoxiaolongzte/spark,bravo-zhang/spark,zero323/spark,byakuinss/spark,UndeadBaneGitHub/spark,UndeadBaneGitHub/spark,bravo-zhang/spark,gioenn/xSpark,pgandhi999/spark,facaiy/spark,ConeyLiu/spark,big-pegasus/spark,guoxiaolongzte/spark,wangyum/spark,aosagie/spark,spark-test/spark,techaddict/spark,pronix/spark,jrshust/spark,zzcclp/spark,wangyum/spark,stanzhai/spark,witgo/spark,aosagie/spark,mdespriee/spark,wzhfy/spark,chuckchen/spark,1haodian/spark,andrewor14/spark,xuanyuanking/spark,ioana-delaney/spark,rednaxelafx/apache-spark,janewangfb/spark,lxsmnv/spark,saltstar/spark,brad-kaiser/spark,aokolnychyi/spark,zhouyejoe/spark,bdrillard/spark,wangmiao1981/spark,ddna1021/spark,mike0sv/spark,ahnqirage/spark,UndeadBaneGitHub/spark,gioenn/xSpark,ddna1021/spark,guoxiaolongzte/spark,poffuomo/spark,dongjoon-hyun/spark,kimoonkim/spark,patrick-nicholson/spark,gioenn/xSpark,gioenn/xSpark,jkbradley/spark,narahari92/spark,Panos-Bletsos/spark-cost-model-optimizer,akopich/spark,gioenn/xSpark,nilsgrabbert/spark,byakuinss/spark,someorz/spark,vinodkc/spark,gioenn/xSpark,rikima/spark,kiszk/spark,spark-test/spark,mzl9039/spark,bravo-zhang/spark,brad-kaiser/spark,shubhamchopra/spark,poffuomo/spark,darionyaphet/spark,map222/spark,ajaysaini725/spark,aray/spark,guoxiaolongzte/spark,sureshthalamati/spark,huang1900/spark,facaiy/spark,tengpeng/spark,bravo-zhang/spark,MLnick/spark,markhamstra/spark,skonto/spark,actuaryzhang/spark,debugger87/spark,dongjoon-hyun/spark,nchammas/spark,sachintyagi22/spark,janewangfb/spark,wzhfy/spark,kevinyu98/spark,maropu/spark,patrick-nicholson/spark,nlalevee/spark,adrian-ionescu/apache-spark,xflin/spark,skonto/spark,ajaysaini725/spark,vinodkc/spark,rednaxelafx/apache-spark,huang1900/spark,nlalevee/spark,setjet/spark,lvdongr/spark,WeichenXu123/spark,spark-test/spark,jianran/spark,xuanyuanking/spark,joseph-torres/spark,narahari92/spark,zero323/spark,SnappyDataInc/spark,HyukjinKwon/spark,minixalpha/spark,liyichao/spark,akopich/spark,JoshRosen/spark,mahak/spark,kimoonkim/spark,HyukjinKwon/spark,brad-kaiser/spark,adrian-ionescu/apache-spark,apache-spark-on-k8s/spark,wangyum/spark,big-pegasus/spark,bOOm-X/spark,guoxiaolongzte/spark,WindCanDie/spark,cin/spark,hvanhovell/spark,ajaysaini725/spark,wangyum/spark,spark-test/spark,techaddict/spark,ajaysaini725/spark,ibm-research-ireland/sparkoscope,jiangxb1987/spark,aokolnychyi/spark,HyukjinKwon/spark,milliman/spark,SHASHANKB/spark,jkbradley/spark,someorz/spark,goldmedal/spark,vinodkc/spark,SHASHANKB/spark,szhem/spark,eyalfa/spark,sahilTakiar/spark,pronix/spark,ibm-research-ireland/sparkoscope,eyalfa/spark,map222/spark,adrian-ionescu/apache-spark,liyichao/spark,LantaoJin/spark,sureshthalamati/spark,SnappyDataInc/spark,WindCanDie/spark,andrewor14/spark,hhbyyh/spark,stanzhai/spark,aray/spark,ddna1021/spark,rednaxelafx/apache-spark,jrshust/spark,liutang123/spark,rezasafi/spark,xflin/spark,mzl9039/spark,haowu80s/spark,tejasapatil/spark,metamx/spark,yanboliang/spark,yanboliang/spark,wangmiao1981/spark,minixalpha/spark,highfei2011/spark,maropu/spark,setjet/spark,ueshin/apache-spark,ioana-delaney/spark,bdrillard/spark,ioana-delaney/spark,cloudera/spark,haowu80s/spark,shaneknapp/spark,pgandhi999/spark,zzcclp/spark,spark-test/spark,michalsenkyr/spark,michalsenkyr/spark,sachintyagi22/spark,apache/spark,bravo-zhang/spark,alunarbeach/spark,witgo/spark,sryza/spark,sureshthalamati/spark,byakuinss/spark,ericvandenbergfb/spark,mike0sv/spark,darionyaphet/spark,cin/spark,yanboliang/spark,apache-spark-on-k8s/spark,akopich/spark,shuangshuangwang/spark,rezasafi/spark,mdespriee/spark,wangmiao1981/spark,JerryLead/spark,holdenk/spark,srowen/spark,JerryLead/spark,shaneknapp/spark,LantaoJin/spark,hvanhovell/spark,sahilTakiar/spark,nchammas/spark,zzcclp/spark,witgo/spark,cloud-fan/spark,xuanyuanking/spark,hhbyyh/spark,Aegeaner/spark,mahak/spark,actuaryzhang/spark,shuangshuangwang/spark,minixalpha/spark,milliman/spark,aosagie/spark,ioana-delaney/spark,UndeadBaneGitHub/spark,jiangxb1987/spark,rikima/spark,shubhamchopra/spark,LantaoJin/spark,publicRoman/spark,nlalevee/spark,maropu/spark,darionyaphet/spark,gengliangwang/spark,joseph-torres/spark,SHASHANKB/spark,saturday-shi/spark,jlopezmalla/spark,bdrillard/spark,ahnqirage/spark,ron8hu/spark,rikima/spark,shaneknapp/spark,wzhfy/spark,publicRoman/spark,ahnqirage/spark,bdrillard/spark,milliman/spark,nlalevee/spark,srowen/spark,shaneknapp/spark,kevinyu98/spark,ptkool/spark,cin/spark,highfei2011/spark,lxsmnv/spark,1haodian/spark,xuanyuanking/spark,cin/spark,metamx/spark,apache/spark,1haodian/spark,kiszk/spark,chuckchen/spark,dbtsai/spark,saturday-shi/spark,yanboliang/spark,ericvandenbergfb/spark,taroplus/spark,zzcclp/spark,lxsmnv/spark,sryza/spark,ioana-delaney/spark,debugger87/spark,stanzhai/spark,shuangshuangwang/spark,rezasafi/spark,ajaysaini725/spark,janewangfb/spark,ueshin/apache-spark,yanboliang/spark,nchammas/spark,kimoonkim/spark,Panos-Bletsos/spark-cost-model-optimizer,ptkool/spark,dongjoon-hyun/spark,joseph-torres/spark,mahak/spark,shubhamchopra/spark,patrick-nicholson/spark,rikima/spark,jkbradley/spark,nilsgrabbert/spark,liyichao/spark,Aegeaner/spark,aray/spark,adrian-ionescu/apache-spark,bdrillard/spark,tengpeng/spark,JoshRosen/spark,andrewor14/iolap,dhruve/spark,ConeyLiu/spark,highfei2011/spark,skonto/spark,zzcclp/spark,andrewor14/iolap,zuotingbing/spark,patrick-nicholson/spark,loneknightpy/spark,mkolod/incubator-spark,taroplus/spark,goldmedal/spark,maropu/spark,minixalpha/spark,pronix/spark,srowen/spark,aokolnychyi/spark,mdespriee/spark,michalsenkyr/spark,adrian-ionescu/apache-spark,ibm-research-ireland/sparkoscope,cloud-fan/spark,ahnqirage/spark,tejasapatil/spark,aokolnychyi/spark,stanzhai/spark,andrewor14/iolap,wangyum/spark,publicRoman/spark,ron8hu/spark,panfengfeng/spark,jiangxb1987/spark,bdrillard/spark,WeichenXu123/spark,esi-mineset/spark,techaddict/spark,lvdongr/spark,aokolnychyi/spark,milliman/spark,big-pegasus/spark,SnappyDataInc/spark,guoxiaolongzte/spark,kimoonkim/spark,ddna1021/spark,saturday-shi/spark,kiszk/spark,goldmedal/spark,mkolod/incubator-spark,markhamstra/spark,zhouyejoe/spark,michalsenkyr/spark,ron8hu/spark,kevinyu98/spark,tejasapatil/spark,zhouyejoe/spark,bOOm-X/spark,facaiy/spark,cloudera/spark