title: Why does the Java compiler sometimes allow the unboxing of null?
body: <p>For example:</p>
  
  <pre><code>int anInt = null;
  </code></pre>
  
  <p>fails at compile time but</p>
  
  <pre><code>public static void main(String[] args) {
    for (int i = 0; i &lt; 10; i++) {
      System.out.println("" + getSomeVal());
    }
  }
  public static int getSomeVal() {
     return new Random().nextBoolean() ? 1 : null;
  }
  </code></pre>
  
  <p>fails (usually) at run time. Trying to return just <code>null</code> will also result in a compile error, so I assume there is something about having multiple paths that causes the compiler to infer that <code>null</code> is potentially an autoboxed <code>int</code>?  Why can javac not fail to compile both cases with the same error?</p>