I'm not quite sure why you don't consider this legal or that this cannot happen, because your parameter is final :
yourClass.compareTo(null);
You should always check for null in scripts that rely on the instance present, preferably before using the instance.
Marking the final parameter prevents you from actively changing the link or changing the value in the method; this is a way to imagine that this code does not contain any side effects from the passed value.
In addition, I notice a problem with your compareTo method; if the object you are comparing is null , then the comparator designates it as equivalent. You will also encounter extreme cases with NaN and == , since two double values may not be completely equivalent.
You probably need something like this:
@Override public int compareTo(final Intersection o) { double distance = t; double distance2 = o == null ? 0 : ot; return Double.compare(distance, distance2); }
source share