title: Java 8 supplier behaviour: final variable might not be initialized
body: <p>Java disallows usage of final variable inside a supplier as it might not be initialized, yet prepending "(this)." to variable makes it compile and run fine. </p>
  
  <p>Furthermore calling such supplier results in NullPointerException instead of compiler error if called before assigning the variable and runs as expected if called after.</p>
  
  <p>Is this behaviour described somewhere?</p>
  
  <p>I am using OpenJDK 1.8.0_151.</p>
  
  <p>Example:</p>
  
  <pre><code>import java.util.function.Supplier;
  class Example {
    final String str;
  
    Supplier&lt;Integer&gt; test1 = () -&gt; str.length();        // DOES NOT COMPILE
    Supplier&lt;Integer&gt; test2 = () -&gt; this.str.length();   // DOES NOT COMPILE
    Supplier&lt;Integer&gt; test3 = () -&gt; (this.str).length(); // DOES NOT COMPILE
    Supplier&lt;Integer&gt; test4 = () -&gt; (this).str.length(); // OK
  
    Example(String str) {
      System.out.println(test4.get()); // NullPointerException
      this.str = str;
      System.out.println(test4.get()); // OK
    }
  }
  
  ---
  
  javac Example.java
  
  Example.java:7: error: variable str might not have been initialized
  Supplier&lt;Integer&gt; test1 = () -&gt; str.length();        // DOES NOT COMPILE
                                  ^
  Example.java:8: error: variable str might not have been initialized
  Supplier&lt;Integer&gt; test2 = () -&gt; this.str.length();   // DOES NOT COMPILE
                                      ^
  Example.java:9: error: variable str might not have been initialized
  Supplier&lt;Integer&gt; test3 = () -&gt; (this.str).length(); // DOES NOT COMPILE
                                       ^
  3 errors
  </code></pre>