title: Findbugs: NP_LOAD_OF_KNOWN_NULL_VALUE - Singleton class Double checking
body: <p>I have a Singleton class with double checking in the constructor. </p>
  
  <p>Findbugs is reporting the below error.</p>
  
  <p><strong><code>Load of known null value in ... NP_LOAD_OF_KNOWN_NULL_VALUE</code></strong></p>
  
  <pre><code>class SomeClass {
    private Object lock = new Object();
    private Map&lt;String,Resource&gt; resourceMap = new HashMap&lt;&gt;();
  
    public Resource getResource(String resourceId) {
      if (resourceMap.get(resourceId) == null) {
        synchronized(lock) {
          if (resourceMap.get(resourceId) == null) 
            Resource resource = new Resource();
            resourceMap.put(resourceId,resource);
        }
      }
      return resourceMap.get(resourceId);
    }
  }
  </code></pre>
  
  <p>I can go with a static object reference, but the requirement is to create a single object for a unique request ids.</p>
  
  <p>Say, request id 1 will be there for multiple request. So, we will have to create a single object for all request ids at run time for this.</p>
  
  <p>Thanks,</p>