title: Kotlin: "synchronized" makes compiler not to be sure about the initialization of a variable
body: <p>Let's imagine the next piece of Kotlin code that performs some query to a database by means a JDBC connector:</p>
  
  <pre><code>    var results : ResultSet
      preparedStatement.clearParameters()
      preparedStatement.setInt(1,value1);
      preparedStatement.setInt(2,value2)
      results = preparedStatement.executeQuery()
      while(results.next()) {
          // parse results
      }
  </code></pre>
  
  <p>that compiles without problems. However, when I try to add thread safety to the access to the preparedStatement:</p>
  
  <pre><code>    var results : ResultSet
      synchronized(preparedStatement) {
          preparedStatement.clearParameters()
          preparedStatement.setInt(1,value1);
          preparedStatement.setInt(2,value2)
          results = preparedStatement.executeQuery()
      }
      while(results.next()) {
          // parse results
      }
  </code></pre>
  
  <p>... I got a <em>"Variable 'results' must be initialized"</em>. It seems the <code>synchronized</code> block acts as a conditional block, but you can be sure that it will be executed once, before the <code>while</code> block.</p>
  
  <p>I have implemented this same block in Java and I don't get the error. Is this a design/implementation error of Kotlin? Or does it have a good reason to behave like that? </p>