rmuir commented on pull request #586: URL: https://github.com/apache/lucene/pull/586#issuecomment-1006157404
> I am fine, except the NPEs should have a message. Why? for users that throw the stacktrace away? > > P.S.: And as said maybe require a message always!? Maybe, we should just decide how it should look? FWIW, if you care about messages, the implicit NPEs from the JDK are superior to anything we do: ``` java.lang.NullPointerException: Cannot load from int array because "x" is null at npe.implicitArray(npe.java:8) ... java.lang.NullPointerException: Cannot invoke "java.lang.Integer.intValue()" because "x" is null at npe.implicit(npe.java:5) ... ``` If we just do `Objects.requireNonNull(x)`, we get: ``` java.lang.NullPointerException at java.base/java.util.Objects.requireNonNull(Objects.java:208) at npe.objects(npe.java:11) ... ``` If we do `Objects.requireNonNull(x, "x")`, it is only slightly better: ``` java.lang.NullPointerException: x at java.base/java.util.Objects.requireNonNull(Objects.java:233) at npe.message(npe.java:14) ... ``` In all cases there is a stack trace, users can't expect to debug anything if they throw that away. So part of me says, don't even bother with message. Especially I would be against formatting fancy strings for every null check. I can go along with just putting local variable's name in the message as a compromise (it is still an ugly hack! the "friendly" NPE feature in java seems half-baked!), but if we want that to be the standard, let's ban the one-arg method in forbidden-apis and fix it consistently everywhere? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org