There is NO bulletproof answer for this question, as it depends on the needs of the program and how it should answer to that exceptional scenario. Saying that, I would say:
If having a null is a programmer's error (I mean something that you will never expect to happen inside your algorithms) I would suggest to leave the .equals
method as a null pointer exception will arise and make you take notice of the problem, I mean, a programmer's error (Those errors that we don't want!, that means that we wrote bad an algorithm), and you should thanks the application for reporting it (instead of an angry real client....)
But if in the other hand your application could work as well, not considering that as a programmer error, then using Object.equals
will fit better to your needs.
The general wisdom suggest that exceptions should at least be logged.
Summary
Try to investigate about different kinds of exceptions. Not all the exceptions are programmer errors.
In Java, usually, the checked exceptions are for all those events that you can anticipate, you can write code that should be able to handle. And the unchecked Exceptions (those that belongs the RuntimeException's family) are for events that you just can not anticipate (like null pointer exceptions), thus it is impossible to write code to handle things that you don't expect (instead you should correct the already existing code, not writing new code!).
.equals
cause of NPE , but withObjects.equals
the code will pass through that as atrue
result... it smells like potential hidden bugobjectOne
andobjectTwo
being used after this line of code? Please edit your question to show a complete method to illustrate.