NullPointerException should not be caughtJAVA-E1070
This code appears to catch a NullPointerException
. This may hide bad errors in code.
Consider removing the offending clause and debugging the underlying cause of the exception instead.
When an NPE is caught solely so it can be silenced, it can indicate that the underlying cause of the exception is not properly known. If an NPE is thrown, it may be that the application is in an inconsistent state which should not be ignored.
Bad Practice
try {
// ...
} catch (NullPointerException n) { // Debug the cause instead!
n.printStackTrace();
}
Recommended
Remove the catch clause that handles NullPointerException
and debug the underlying issue instead.
Exceptions
If the reason for throwing NPEs is within library code or within code that you have no control over, it may not be possible to easily fix the issue. In such cases, consider ignoring this issue with a skipcq
comment above the offending line.
// skipcq
somethingThatThrows();