Java short circuit evaluation

后端 未结 7 1442
深忆病人
深忆病人 2021-01-07 23:26

I thought Java had short circuit evaluation, yet this line is still throwing a null pointer exception:

if( (perfectAgent != null) && (perfectAgent.ge         


        
7条回答
  •  伪装坚强ぢ
    2021-01-07 23:56

    Big mistery. I copied your line of code and tested with perfectAgent == null, entry == null, entry.getKey() == null and combinations of those: No NPE in my test bed (Java 1.6).

    Whatever annoying bug it is, I doubt that it has something to do with short circuit evaluation. If it's this line causing NPE, than, as far as I can say, perfectAgent is not null. Good luck and - show us the bug once you've catched it :)

提交回复
热议问题