Objects.nonNull()

Brian Goetz brian.goetz at oracle.com
Mon Jan 17 05:26:05 UTC 2011


> I still don't like checkNonNull.  It checks whether its argument is
> non-null, but then what does it do?  Throw an exception if it is
> non-null?  Throw an exception if it isn't?  Do something else?
>
> My aversion to checkNonNull naming pattern comes from experience.  Long,
> long ago in a code base far, far away I wrote a big set of unit tests
> using this pattern.  Coming back to it months later I had to read the
> code very closely and keep reminding myself that the checkFoo procedures
> were ensuring the Foo condition rather ensuring nonFoo.

I see your point now.  Perhaps you'd prefer requireNonNull() for the 
throwing version?

   public void fooWrapper(String s, String t) {
      foo(requireNonNull(s), requireNonNull(t));
   }

I get your point about maybe we should just remove this, but I do think 
that a method that acts on all object references ignorant of the 
reference type, fits within the mission of juO.



More information about the core-libs-dev mailing list