Auto boxing can fool you

Assigning null objects to primitives

public class FalseSafetyWithAutoBoxing {
  private static class Car {
    public Car(Double price) {
      double value = price;
    }
  }

  public static void main(String[] args) throws Exception {
    Double price = null;
    Car car = new Car(price);
  }
}

When you run this, you get:

$ javac FalseSafetyWithAutoBoxing.java && java FalseSafetyWithAutoBoxing
Exception in thread "main" java.lang.NullPointerException
  at FalseSafetyWithAutoBoxing$Car.<init>(FalseSafetyWithAutoBoxing.java:12)
  at FalseSafetyWithAutoBoxing.main(FalseSafetyWithAutoBoxing.java:18)

~ /home 🏠 ~ talks 💬 ~ bash ~ craftsmanship ~ db ~ dongxi ~ emacs ~ escenic ~ iam ~ java ~ js ~ language ~ latex ~ ldap ~ life ~ linux ~ llm ~ mac-os-x ~ mt-foo ~ network ~ norsk ~ python ~ quotes ~ running ~ security ~ travel ~ unix ~ various ~ vcs ~ webdesign ~ windows ~ discoveries ~ cv 🧙 ~

Licensed under CC BY Creative Commons License ~ 📡 RSS feed ~ ✉ torstein.k.johansen @ gmail ~ 🐘 @skybert@hachyderm.io ~ 🎥 youtube.com/@skybert