title: How can we get NPE, race condition
body: <p>I was asked the following question on an interview. Given the following code, if methods <code>add</code> and <code>doAction</code> are being invoked by multiple threads, how can we get a <code>NullPointerException</code> when printing <code>toString</code>?**</p>
  
  <pre><code>public class Test{
       private List&lt;Object&gt; obj = new ArrayList&lt;Object&gt;();
  
       public void add(Object o){
             obj.add(o);
       }
  
       public void doAction(){
             for(Object o: obj){
                   System.out.println(o.toString()); // maybe NPE, why?
             }
       }
  
  }
  </code></pre>
  
  <p>Cut out all other multithread concerns.</p>