It is un-progammer-like to write may not be null for the frequent null-checks that are performed with Throw.whenNull(). For example in Point2d.closestPointOnSegment():
Throw.whenNull(segmentPoint1, "linePoint1 may not be null");
Throw.whenNull(segmentPoint2, "linePoint2 may not be null");
Note also that the names are not correct in the provided messages. It is not possible in java to know what the name of a variable was at the level of the calling class. That is, Throw cannot know about the names segmentPoint1 and segmentPoint2. Therefore, simplifying this to Throw.whenNull(segmentPoint1) does not suffice.
This makes it very clear whether the name is correctly given to a programmer. Throw can figure out whether to add " may not be null" by checking whether there is a blank in the provided message. Specifically using a regular expression pattern matching with \s. Note that this is only done when in fact a NullPointerException will be thrown. More elaborate messages, that should contain a \s, are still possible in this way and will not be appended with " may not be null".
It is un-progammer-like to write
may not be null
for the frequent null-checks that are performed withThrow.whenNull()
. For example inPoint2d.closestPointOnSegment()
:Note also that the names are not correct in the provided messages. It is not possible in java to know what the name of a variable was at the level of the calling class. That is,
Throw
cannot know about the namessegmentPoint1
andsegmentPoint2
. Therefore, simplifying this toThrow.whenNull(segmentPoint1)
does not suffice.What we can do is the following:
This makes it very clear whether the name is correctly given to a programmer.
Throw
can figure out whether to add" may not be null"
by checking whether there is a blank in the provided message. Specifically using a regular expression pattern matching with\s
. Note that this is only done when in fact aNullPointerException
will be thrown. More elaborate messages, that should contain a\s
, are still possible in this way and will not be appended with" may not be null"
.