[ checkstyle-Feature Requests-3182213 ] New Check: Illegal throwing.

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[ checkstyle-Feature Requests-3182213 ] New Check: Illegal throwing.

SourceForge.net
Feature Requests item #3182213, was opened at 2011-02-15 05:00
Message generated for change (Comment added) made by romanivanov
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=397081&aid=3182213&group_id=29721

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.
Category: Check
Group: None
Status: Pending
Priority: 5
Private: No
Submitted By: http://moradanen.sopovs.com/ ()
Assigned to: Nobody/Anonymous (nobody)
Summary: New Check: Illegal throwing.

Initial Comment:
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:
    <module name="Regexp">
      <property name="format" value="throw new NullPointerException"/>
      <property name="message" value="Please throw IllegalArgumentException or IllegalStateException instead of NullPointerException!"/>
      <property name="illegalPattern" value="true"/>
    </module>

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();
throw ex;

----------------------------------------------------------------------

Comment By: Roman Ivanov (romanivanov)
Date: 2012-04-19 22:04

Message:
Released at 1.0.5,
http://sevntu-checkstyle.github.com/sevntu.checkstyle/update-site/ 

Oliver, thanks for pointing! I will test your check.

----------------------------------------------------------------------

Comment By: Oliver Burn (oburn)
Date: 2012-04-16 03:59

Message:
Is this not already covered by
http://checkstyle.sourceforge.net/config_coding.html#IllegalInstantiation

----------------------------------------------------------------------

Comment By: Daniil Yaroslavtsev (daniilyar)
Date: 2012-04-08 11:13

Message:
Done as ForbidInstantiationCheck. You can use it to forbid NPE
instantiation ("java.lang.NullPointerException" is the default check
option).

Patch is here:
https://sourceforge.net/tracker/?func=detail&aid=3515916&group_id=29721&atid=397080

----------------------------------------------------------------------

Comment By: Roman Ivanov (romanivanov)
Date: 2011-02-17 23:45

Message:
it will be useful to detect even this:
try {
} catch(NullPointerException ex) {
    throw ex;
}

----------------------------------------------------------------------

You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=397081&aid=3182213&group_id=29721

------------------------------------------------------------------------------
For Developers, A Lot Can Happen In A Second.
Boundary is the first to Know...and Tell You.
Monitor Your Applications in Ultra-Fine Resolution. Try it FREE!
http://p.sf.net/sfu/Boundary-d2dvs2
_______________________________________________
Checkstyle-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/checkstyle-devel