Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Submitted By: http://moradanen.sopovs.com/ ()
Assigned to: Nobody/Anonymous (nobody)
Summary: New Check: Illegal throwing.
In our team it is considered a bad practice to throw NullPointerException ,and we should use IllegalArgumentException and IllegalStateException instead. The request it to make a configurable check to forbid not only declaring certain types of exceptions, but also throwing it.
We use the following piece of configuration inside the module TreeWalker:
<property name="format" value="throw new NullPointerException"/>
<property name="message" value="Please throw IllegalArgumentException or IllegalStateException instead of NullPointerException!"/>
<property name="illegalPattern" value="true"/>
However we are concerned about efficiency of such way, it is not very convenient to alter this check, it raises warnings for commented code (it is a bad practice on its own, but it is a _separate_ bad practice) and it do not raise warnings for something like this:
NullPointerException ex = new NullPointerException();