title: Thread safety issues in reference assignment using method call
body: <p>I have the following code:</p>
  
  <pre><code>class SomeClass {
      private Map&lt;String, String&gt; someMap = null;
  
      public String getValue(String key) {
          if (someMap == null) {
              someMap = initialize(); // initialize() is some method which returns a proper map.
          }
          return someMap.get(key);
      }
  }
  </code></pre>
  
  <p>Assuming I don't care about <code>someMap</code> getting initialized more than once, are there any other thread-safety issues that I need to be concerned about here.</p>
  
  <p>As per <a href="https://stackoverflow.com/a/4756578/715769">what-operations-in-java-are-considered-atomic</a> , Reference assignment is certainly atmoic. Is the assignment to <code>someMap</code> guaranteed to happen after the method call to <code>initialize()</code> (seems logical to me). Is there any possibility that a thread can see a partially constructed <code>someMap</code>. Does it matter if instead of a map, I have some other type of object.</p>