title: Write to static field from instance method
body: <p>I have my code as below. I see </p>
  
  <pre><code>public MyClass{
  
      private static DataSource dataSource = null;
  
      private static DataSource getDataSource(){
          if (dataSource == null) {
              try {
                  dataSource = // something.
              } catch (Exception e) {
                  // some exception.
              }
          }
  
          return dataSource;
      }
  
      public List doSomething(){
  
          // ...
  
          if(dataSource == null){
              dataSource = getDataSource();
          }
  
          dataSource.getConnection();
          // ...
  
      }
  }
  </code></pre>
  
  <p>I see following message in sonar anaylsis.</p>
  
  <pre><code>Dodgy - Write to static field from instance method
  
  This instance method writes to a static field. This is tricky to get correct if multiple instances are being manipulated, and generally bad practice.
  findbugs:ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD Sep12 Reliability &gt; Architecture
  </code></pre>
  
  <p>I see everything is okay in this implementation except that we are changing the static variable in doSomething method. How do we fix this ?</p>