Request: Best practices audits


While Idea's code inspection tool offers some great hints for improving
code, it is far from complete. I'd like to see it implement much more
of the rules from: The Java Language Specification, The Elements of
Java Style (Vermeulen et al.), and Effective Java (Bloch).

A new tool called Teamstudio Analyzer (which unfortunately does not
integrate with Idea yet [although I've emailed them to request Idea
support]) does such best practices audits and includes the rules listed
below. While some may duplicate what Idea's code inspection catches,
many are useful additions. Please, IntelliJ, add these in the next
major update after Aurora.

Thank you.

-Scott Steinman

0001 Package name does not contain lowercase letters
0002 Package name does not begin with a top level domain name or
country code
0003 Minimize use of on-demand (.*) imports
0004 Unnecessary import from java.lang
0005 Imports not in specified order
0006 Empty finally blocks
0007 Should not declare public field
0008 Empty catch block
0009 Protected member in final class
0010 Non-instantiable class does not contain a non-private static member
0011 Abstract class does not contain an abstract method
0012 Non-constructor method with same name as declaring class
0013 Non-blank final field is not static
0014 Class with only static members has non- private constructor
0015 Non-private class contains public nested class
0016 Abstract class contains non-protected constructor
0017 Class name does not have required form
0018 Method name does not have required form
0019 Interface name does not have required form
0020 Field name does not have required form
0021 Interface method name does not have required form
0022 Static final field name does not have required form
0023 Empty finalize method
0024 Class has no fields
0025 Method override is empty
0026 Finalize method with parameters
0029 Private method not used
0030 Private field not used
0031 Case statement not properly closed
0032 Switch statement missing default
0033 Default: not last case in switch statement
0034 Missing braces in if statement
0035 Missing braces in for statement
0036 Missing braces in while statement
0037 Missing else after else if statement
0038 Non-case label in switch statement
0039 Break statement with label
0040 Switch statement contains N cases (maximum: M)
0041 Nested synchronized block
0042 Empty synchronized statement
0043 Inner class does not use outer class
0044 Serializable class with no instance variables
0045 Serialized class with only transient fields
0046 Name of class not derived from Exception ends with 'Exception'
0047 Serialized class derives from invalid base class
0048 Name of class derived from Exception does not end with ?Exception?
0049 Nested block at depth N (maximum: M)
0050 Class derives from java.lang.Error
0051 Class derives from java.lang.RuntimeException
0052 Class derived from java.lang.Throwable
0053 Unused label
0054 Inheritance depth N exceeds maximum M
0055 Class should be interface
0056 Unnecessary abstract modifier for interface
0057 Empty public constructor
0058 Constructor calls super()
0061 Inaccessible member in anonymous class
0062 Public class missing public member or protected constructor
0063 Identifier name should not contain $
0064 N variations of identifier name (maximum: M)
0065 Unnecessary final modifier for method in final class
0066 Unnecessary modifier for interface nested type
0067 Array descriptor on identifier name
0068 Modifiers not declared in recommended order
0069 Obsolete modifier usage
0071 Strings compared with ==
0073 Integer division in floating-point context
0074 Use of Object.notify()
0075 Constructor or method parameter hides field
0076 Use of magic number
0077 Private field not used in declaring class
0078 Floating point values compared with ==
0079 Use of instance to reference static member
0080 Import declaration not used
0081 Boolean literal in comparison
0082 Unnecessary widening cast
0083 Unnecessary instanceof test
0084 Should use compound assignment operator
0085 Use of sun.* class
0087 Use of Thread.sleep()
0089 Use of restricted package
0092 Use of restricted class
0093 Redundant assignment
0094 Field hides a superclass field
0095 Uninitialized private field
0096 Field in nested class hides outer field
0098 Minimize use of implicit field initializers
0100 Class contains N non-final fields (maximum: M)
0101 Unnecessary modifier for field in interface
0102 Last statement in finalize() not super.finalize()
0103 Explicit call to finalize()
0104 Finalize() only calls super.finalize()
0105 Duplicate import declaration
0106 Unnecessary import from current package
0108 Incorrect javadoc: no @param tag for 'parameter'
0109 Incorrect javadoc: no parameter 'parameter'
0110 Incorrect javadoc: no @return tag
0111 Incorrect javadoc: @return tag for void method
0112 Incorrect javadoc: no exception 'exception' in throws
0113 Incorrect javadoc: no @author tag
0114 Incorrect javadoc: no @version tag
0115 Incorrect javadoc: no @throws or @exception tag for 'exception'
0116 Missing javadoc: field 'field'
0117 Missing javadoc: method 'method'
0118 Missing javadoc: type 'type'
0119 Control variable changed within body of for loop
0123 Use all three components of for loop
0125 Continue statement with label
0126 Method declares unchecked exception in throws
0128 Public constructor in non-public class
0130 Non-static method does not use instance fields
0131 Compatible method does not override base
0133 Non-synchronized method overrides synchronized method
0135 Only one of Object.equals and
Object.hashCode overridden: missing 'method'
0136 N methods defined in class (maximum: M)
0137 Non-abstract class missing constructor
0138 N parameters defined for methods (maximum: M)
0139 Definition of main other than public static void
main(java.lang.String[])
0141 Unnecessary modifier for method in interface
0143 Synchronized method
0145 Tab character used in source file
0146 Code line exceeds maximum M character(s)
0147 Comment line exceeds maximum M character(s)
0148 Javadoc line exceeds maximum M character(s)
0149 Single-line comment extends beyond maximum column M
0150 java.lang.Error (or subclass) thrown
0153 Inefficient conversion of integer to string
0159 Inefficient conversion of string to integer
0160 Method does not throw specified exception
0161 Conditional wait() not in loop
0163 Empty statement
0165 Conflicting return statement in finally block
0166 Generic exception caught
0167 ThreadDeath not rethrown
0169 Unnecessary catch block: exception 'exception'
0170 Caught exception not derived from java.lang.Exception
0171 Unused local variable
0173 Unused method parameter
0174 Assigned local variable never used
0175 Successive assignment to variable
0176 Local variable name does not have required form
0177 Variable declaration missing initializer
0179 Local variable hides visible field
0180 Non-public session bean
0181 Invalid modifier for session bean type declaration
0182 Session bean lacks ejbCreate method(s)
0183 Session bean lacks public no-arg constructor
0184 Session bean defines finalize()
0185 Session bean ejbCreate method not declared void
0186 Remote home interface create method does not return remote
interface type
0187 Home interface create method does not throw
javax.ejb.CreateException
0188 Non-public entity bean
0189 Finder method in abstract entity bean
0190 Entity bean defines finalize()
0191 Entity bean ejbPostCreate does not match any ejbCreate method
0192 Enterprise bean defines non-public ejbCreate method
0193 Entity bean declares void ejbCreate method
0194 Invalid modifier for entity bean ejbCreate/ejbPostCreate method
0195 Entity bean declares non-void ejbPostCreate method
0196 Entity bean lacks ejbFindByPrimaryKey method
0197 Entity bean defines non-public finder method
0198 Invalid modifier for entity bean finder method
0199 Home interface find method does not throw javax.ejb.FinderException
0200 Entity bean defines non-public ejbSelect method
0202 Entity bean ejbSelect method does not throw
javax.ejb.FinderException
0205 Local home interface create method does not return local interface
type
0206 Entity bean defines non-public ejbPostCreate method
0207 Remote interface method does not throw java.rmi.RemoteException
0208 Remote home interface method does not throw
java.rmi.RemoteException
0209 Local bean interface method throws java.rmi.RemoteException
0210 Local home interface method throws java.rmi.RemoteException
0211 Entity bean lacks public no-arg constructor
0213 Entity bean ejbCreate does not match any ejbPostCreate method
0214 Entity bean declares non-abstract ejbSelect method
0215 Entity bean ejbCreate method does not throw
javax.ejb.CreateException
0216 Entity bean declares non-public ejbHome method
0217 Invalid modifier for entity bean ejbHome method
0218 Entity bean home method throws java.rmi.RemoteException
0219 Message bean does not implement javax.jms.MessageListener
0220 Non-public message bean
0221 Invalid modifier for message bean
0222 Message bean lacks public no-arg constructor
0223 Message bean defines finalize()
0224 Message bean lacks ejbCreate()
0225 Message bean ejbCreate method not declared void
0226 Message bean ejbCreate method declared with arguments
0227 Name of bean type should end with 'Bean'
0228 Name of home interface should end with 'Home'
0229 Name of local home interface should be LocalHome or LocalHome 0230 Name of type not derived from bean type ends with 'Bean' 0231 Name of interface not extending EJBHome or EJBLocalHome ends with 'Home' 0232 Name of interface not extending EJBLocalHome matches LocalHome or ]]>LocalHome

9 comments

Here's a similar list for JTest. I'd love IDEA's inspections to cover more of these. I actually coded up most of them as PSIVisitors, dumping the errors/weaknesses found to a text file. Cool, and occasionally useful, without being able to hook into the inspection GUI there wasn't much point in going farther. If JetBrains were to open up their API enough so that users could add inspections, I'd be happy to ship almost all of the items on both these lists.



Dave Griffith, dave.griffith@cnn.com

0

Why not put these in a Tracker Feature request, so we can vote.

(in the old style...)

+1

Mike

0

>... so we can vote.

Maybe because votes are limited?

Tom

0

I'm not suggesting to not post it here. But also post it to the tracker.

That's all.

I think it is a great idea to expand the inspection tool. I currently use it quite frequently.

Mike

0

Basically because there's too many of them to do one-by-one, and the value of this sort of thing increases rapidly as the number of supported tests increases. In other words, there's not much value in JetBrains coding up any one of these inspections, but there's a lot of cost in them coding up all of them. There is a tracker request for a pluggable inspection API, which would seem to be more likely to get implemented, and which would enable these to be picked off one-by-one by appropriately rabid members of the use community (like, um, me).

0

PMD
http://pmd.sourceforge.net
offers a pluggable and extensible way to do this. If the basis - core
rules - were integrated into IDEA, users could write and add their own -
auditing - rules, ? la plugin.

Also to note : advanced duplicate finding withCPD - Cut & Paste
Detection -, a pmd subproject.
It's performant and also available standalone, with WebStart
http://pmd.sourceforge.net/cpd.html
http://pmd.sourceforge.net/cpd.jnlp

Alain Ravet

0

Mike, I completely agree with you. As others, too, I miss the
enthusiastic discussions pro and contra a rfe.

Tom

0

Yeah, I looked into PMG, but basically what it provides is a parser, some read-only output displays, and a rule language. IDEA's internal parser is clearly much better (incremental, caching, kinda-error-tolerant, etc.), the inspection GUI is much better (cross-linking, auto-fix buttons), and I can't see much value in PMG's (more-than-a-bit confusing) rule language over writing the rules in Java.

0

which would enable these to
be picked off one-by-one by appropriately rabid
members of the use community (like, um, me).


I am currently working on a metrics suite which I would like to integrate into IDEA. It would be great if you could share some information on which metrics from your list you already implemented... please contact me at intidea@pmayer.net - Thanks!

-Phil

0

Please sign in to leave a comment.