title: Unboxing a null boxed object throws unexpected NullPointerException
body: <p>If you run the following code,</p>
  
  <pre><code>public class Foo{
      public static void main(String[] args){
          int id = new Bar().getId(); // throws unexpected NullPointerException
      }
  
      private static class Bar{
          private final Integer id;
  
          public Bar(){
              this(null);
          }
  
          public Bar(Integer id){
              this.id = id;
          }
  
          public Integer getId(){
              return id;
          }
      }
  }
  </code></pre>
  
  <p>you will get the following stacktrace,</p>
  
  <pre><code>Exception in thread "main" java.lang.NullPointerException
      at Foo.main(Foo.java:3)
  </code></pre>
  
  <p>How come there's no compiler warning or anything? IMHO it's a pretty nasty subtlety with unboxing, or maybe I'm just naive. </p>
  
  <hr>
  
  <p>Adding on to the answer provided by <a href="https://stackoverflow.com/a/14992146/584862">@Javier</a>, if you're using Eclipse, you need to do the following to enable this:</p>
  
  <ol>
  <li>Navigate to <kbd>Window</kbd> > <kbd>Preferences</kbd> > <kbd>Java</kbd> > <kbd>Compiler</kbd> > <kbd>Errors/Warnings</kbd></li>
  <li>Expand <strong>Potential programming problems</strong></li>
  <li>Toggle <strong>Boxing and unboxing conversions</strong> to either "Warning", or "Error"</li>
  <li>Tap "OK"</li>
  </ol>