JAVA编码规范

 

JAVA 编码标准规范
 
一、 JAVA 编码标准规则
1.   JavaBeans [BEAN]
2.   编码约定 / 惯例 Coding Conventions [CODSTA]
3.   契约设计 / Design by Contract [DBC]
4.   Enterprise JavaBeans [EJB]
5.   异常 / Exceptions [EXCEPT]
6.   格式化 / Formatting [FORMAT]
7.   碎片回收集 / Garbage Collection [GC]
8.   全面静态分析 / Global Static Analysis [GLOBAL]
9.   初始化 / Initialization [INIT]
10.  国际化 / Internationalization [INTER]
11. JAVA2 微型平台 / Java 2 Micro Edition [J2ME]
12. JAVA 文档注释 / Javadoc Comments [JAVADOC]
13. JAVA 数据库连接 / Java Database Connectivity [JDBC]
14. JavaServer Pages [JSP]
15. JavaServer Page Metrics [JMETRICS]
16. Junit 测试用例 / JUnit Test Case [JUNIT]
17.  类结构 / Class Metrics [METRICS]
18.  不同特性 / Miscellaneous [MISC]
19.  命名约定 / 惯例 Naming Conventions [NAMING]
20.  面向对象编程 / Object Oriented Programming [OOP]
21.  最优化 / Optimization [OPT]
22.  可能存在的 BUG/ Possible Bugs [PB]
23.  简便 / Portability [PORT]
24.  安全 / Security [SECURITY]
25.  序列化 / Serialization [SERIAL]
26. Servlets [SERVLET]
27. Struts 框架 / Struts Framework [STRUTS]
28.  线程与同步 / Threads & Synchronization [TRS]
29.  从未使用的代码 / Unused Code [UC]
30.  安全(必要的许可) / Security (License Required) [SLR]
31.  安全策略规范 Security/ Policy Rules (License Required) [SPR]
32. Web 安全(必要的许可) / Web Security (License Required) [WSLR]
 
二、内置与自定义的标准组
1. 内置的Jtest配置/ Built-in Jtest Configurations
2. 测试驱动开发(TDD)/ Test Driven Development (TDD)
3. Parasoft的自动错误预防组/ Parasoft's AEP group
4. Scope Examples group
5. 其他配置/ Other configurations
6.       自定义编码标准分析:概要/ Customizing coding standard analysis: overview
 
一、 JAVA 编码标准规则
 
1. JavaBeans [BEAN]
1-1.在JavaBean类中为listener方法名使用适当的签名/Use appropriate signatures for listener method names in JavaBean classes [BEAN.BLNC-1]
1-2.确保JavaBean类实现了'java.io.Serializable'/Ensure that JavaBean classes implement 'java.io.Serializable' [BEAN.SERIALIZABLE-2]
1-3.在JavaBean类中覆写'Object.equals()' /Override 'Object.equals()' in JavaBean classes [BEAN.EQUALS-4]
1-4.在JavaBean类中不使用JDBC代码/Do not use JDBC code in JavaBean classes [BEAN.JDBC-4]
1-5.在私有字段中定义get和set方法/Define get and set methods for each private field [BEAN.NFM-4]
 
2. Coding Conventions [CODSTA]
2-1.避免在其他表达式中嵌套赋值或内部赋值/ Avoid nested assignments or assignments embedded in other expressions [CODSTA.NEA-1]
2-2.适当性的定制编辑单元成分/ Order compilation unit elements appropriately [CODSTA.ORCU-1]
2-3.在一个语句中不要断言不同类型中的多个变量/ Do not declare multiple variables of different types in one statement [CODSTA.VDT-1]
2-4.为Cloneable类声明'clone() throws CloneNotSupportedException'/ Declare 'clone() throws CloneNotSupportedException' for Cloneable class [CODSTA.CLONE-2]
2-5.确保没有终结Cloneable类中的'clone()'方法声明了'CloneNotSupportedException'/ Ensure 'clone()' method of non-final Cloneable class declared to throw 'CloneNotSupportedException' [CODSTA.CLONET-2]
2-6.避免在长整型常量后有小字母的"l"或字母的"1"/ Avoid having a lower-case "l" or the number "1" at the end of a "long" integer constant [CODSTA.LONG-2]
2-7.避免字面意义的常量/ Avoid literal constants [CODSTA.USN-2]
2-8.不要使用"break" 和(或则) "continue"与符号/ Do not use "break" and/or "continue" with labels [CODSTA.ABCL-3]
2-9.在"if"语句中不要使用复杂的条件表达式/ Do not use complicated conditional expressions in "if" statements [CODSTA.ACCS-3]
2-10.在一个catch块中不要使用instanceof去检查异常类型/ Do not use instanceof in a catch block to check the exception type [CODSTA.AIOC-3]
2-11.不要覆写父类中的非抽象方法/ Do not override non "abstract" methods of a parent class with "abstract" methods [CODSTA.AMMO-3]
2-12.用较少的特定类型实现松散耦合/ Use less specific types to accomplish loose coupling [CODSTA.AUVT-3]
2-13."final"以大写字符名声明字段/ Declare fields with uppercase character names as "final" [CODSTA.CFNF-3]
2-14.在类中使用链构造器实现多个构造器/ Use chain constructors in classes with multiple constructors [CODSTA.CHAIN-3]
2-15.在嵌套的表达式中避免使用增量或减量的算法/ Avoid using increment or decrement operators in nested expressions [CODSTA.CID-3]
2-16.使用'clone()'方法仅仅是实现'Cloneable'接口/ Use the 'clone()' method only to implement 'Cloneable' interface [CODSTA.CLONE2-3]
2-17.强制或避免使用条件算法/ Enforce or avoid usage of conditional operators [CODSTA.CX-3]
2-18.只要可能就定义一个非自变量构造器/ Define a no argument constructor whenever possible [CODSTA.DCTOR-3]
2-19.适当的定制类元素/ Order class elements appropriately [CODSTA.FO-3]
2-20.不要在一个语句中声明多个变量Do not declare multiple variables in one statement [CODSTA.MVOS-3]
2-21.在构造器执行期间不要调用方法那样可能会引起意料不到的NullPointerExceptions/ Do not call methods that might cause unexpected NullPointerExceptions during constructor execution [CODSTA.NCNFC-3]
2-22.避免"throws"异常;而用'Exception'的子几集/ Avoid "throws" Exceptions; use subclasses of 'Exception' [CODSTA.NTX-3]
2-23.以名字来组织方法/ Organize methods by name [CODSTA.OGM-3]
2-24.当你覆写'Object.hashCode()'时也覆写'Object.equals()'/ Override 'Object.equals()' when you override 'Object.hashCode()' [CODSTA.OVERRIDE2-3]
2-25.确保一个类中仅有的"private"构造器声明为"final"/ Ensure that a class which has only "private" constructors is declared as "final" [CODSTA.PCF-3]
2-26.避免"switch"语句有多个"case"语句/ Avoid "switch" statements with many "case" statements [CODSTA.SMC-3]
2-27.每个文件中至多有一个类型/ Do not have more than one type in each file [CODSTA.AMOC-4]
2-28.不要使用符号语句/ Do not use label statements [CODSTA.AULS-4]
2-29.避免嵌套的块/ Avoid nested blocks [CODSTA.BLOCK-4]
2-30.在比较中适当的一边放置常量/ Place constants on the appropriate side of comparisons [CODSTA.CS-4]
2-31.所有形式参数声明为"final"/ Declare all formal parameters as "final" [CODSTA.FPF-4]
2-32.避免或强制在import语句中使用'*'/ Avoid or enforce usage of '*' form of import statements [CODSTA.IMPTD-4]
2-33.在一个"abstract"类中不要从构造器中调用一个"abstract"方法/ Do not call an "abstract" method from a constructor in an "abstract" class [CODSTA.NCAC-4]
2-34.不要使用'Exception', 'RuntimeException', 或者 'Throwable'在 "catch"语句中/Do not use 'Exception', 'RuntimeException', or 'Throwable' in "catch" statement [CODSTA.NCE-4]
2-35.避免非静态初始化/ Avoid non-static initializers [CODSTA.NSI-4]
2-36.避免多个负载的方法有同样数字的参数/ Avoid multiple overloaded methods with the same number of parameters [CODSTA.OVERLOAD-4]
2-37.当你覆写'Object.equals()'时也覆写'Object.hashCode()'/ Override 'Object.hashCode()' when you override 'Object.equals()' [CODSTA.OVERRIDE-4]
2-38.在最后放置'main()'方法/ Place the 'main() 'method last [CODSTA.PML-4]
2-39.避免或强制使用"this"和"super"表达式/ Avoid or enforce the use of "this" and "super" expressions [CODSTA.UATS-4]
2-40.避免所有的类型有一个非默认的包名/ Ensure all types have a non default package name [CODSTA.UNDPN-4]
2-41.在if-else中避免使用负逻辑/ Avoid using negative logic in if-else statement [CODSTA.ANL-5]
2-42.在一个"interface"应定义常量/ Define constants in an "interface" [CODSTA.DCI-5]
2-43.在单一的方法中不要使用过多的'!'否定算法/ Do not use too many negation operators '!' in a single method [CODSTA.DUN-5]
2-44.不要使用一个"interface"去定义常量/ Do not use an "interface" to define constants [CODSTA.ISACF-5]
2-45.在"public"和"protected"方法间放置'finalize()'方法/ Place 'finalize()' methods between "public" and "protected" methods [CODSTA.ORFIM-5]
2-46.以整齐的字母序列呈现"import"语句/ Present "import" statements in alphabetical order [CODSTA.ORIMP-5]
2-47.覆写'toString ()'/ Override 'toString ()' [CODSTA.OTOSM-5]
 
3. Design by Contract [DBC]
3-1.在契约设计中使用正确的约定语法/ Use correct syntax in the DbC contracts [DBC.SYNTAX-1]
3-2.为所有"public"方法提供一个'@post'约定/ Provide an '@post' contract for all "public" methods [DBC.PUBMPOST-2]
3-3.为所有"public" 类提供一个'@invariant'约定/ Provide an '@invariant' contract for all "public" classes [DBC.PUBC-2]
3-4.为所有"public"方法提供一个'@pre'约定/ Provide an '@pre' contract for all "public" methods [DBC.PUBMPRE-2]
3-5.为所有"protected"类提供一个'@invariant'约定/Provide an '@invariant' contract for all "protected" classes [DBC.PROC-3]
3-6.为所有"protected"方法提供一个'@post'约定/ Provide an '@post' contract for all "protected" methods [DBC.PROMPOST-3]
3-7.为所有"protected"方法提供一个'@pre'约定/ Provide an '@pre' contract for all "protected" methods [DBC.PROMPRE-3]
3-8.为所有私有类包提供一个'@invariant'约定/ Provide an '@invariant' contract for all package-private classes [DBC.PKGC-4]
3-9.为所有私有方法包提供一个'@post'约定/ Provide an '@post' contract for all package-private methods [DBC.PKGMPOST-4]
3-10.为所有私有方法提供一个'@pre'约定/ Provide an '@pre' contract for all package-private methods [DBC.PKGMPRE-4]
3-11.为所有"private"类提供一个'@pre'约定/ Provide an '@invariant' contract for all "private" classes [DBC.PRIC-5]
3-12.为所有"private"方法提供一个'@post'约定/ Provide an '@post' contract for all "private" methods [DBC.PRIMPOST-5]
3-13.为所有"private"方法提供一个'@pre'约定Provide an '@pre' contract for all "private" methods [DBC.PRIMPRE-5]
 
4. Enterprise JavaBeans [EJB]
4-1.声明bean类为"public"/ Declare bean classes "public" [EJB.CDP-1]
4-2.不要以"abstract"声明bean类/ Do not declare bean classes as "abstract" [EJB.CNDA-1]
4-3.不要以"final"声明bean类/ Do not declare bean classes as "final" [EJB.CNDF-1]
4-4.声明'ejbCreate()'方法为"public",但即不能为"static"也不能为"final"/ Declare 'ejbCreate()' methods "public", but neither "static" nor "final" [EJB.CRTE-1]
4-5.声明finder方法为"public",不过即不能为"static"也不能为"final"/ Declare finder methods "public" and neither "final" nor "static" [EJB.FNDM-1]
4-6.在一个bean类中实现一个或多个'ejbCreate ()'方法/ Implement one or more 'ejbCreate ()' methods in bean classes [EJB.IECM-1]
4-7.在一个实体bean类中实现一个或多个'ejbPostCreate()'方法/ Implement one or more 'ejbPostCreate()' methods in EntityBean classes [EJB.IEPM-1]
4-8.在所有消息驱动bean类中实现'ejbCreate()'方法/ Implement the 'ejbCreate()' method for all Message-driven bean classes [EJB.MDBC-1]
4-9.在实体bean类中为每个'ejbCreate'方法定义一个匹配的'ejbPostCreate()'方法/ Define a matching 'ejbPostCreate()' method for each 'ejbCreate' method in entity bean classes [EJB.MEC-1]
4-10.在bean类中不要定义'finalize ()'方法/ Do not define 'finalize ()' method in bean classes [EJB.MNDF-1]
4-11.为远程interface和远程home interface的方法抛出'java.rmi.RemoteException'/ Throw 'java.rmi.RemoteException' in the methods of remote interface and remote home interface [EJB.MRE-1]
4-12.避免在消息驱动Bean的'ejbCreate()'方法有自变量/ Avoid arguments in MessageDrivenBeans' 'ejbCreate()' method [EJB.NAC-1]
4-13.传入无参数则声明一个"public"构造器/ Declare a "public" constructor that takes no parameters [EJB.NFDC-1]
4-14.声明'ejbPostCreate()'为"public",不过即不能为"static"也不能为"final"/ Declare 'ejbPostCreate()' "public" and neither "static" nor "final" [EJB.PCRTE-1]
4-15.在一个bean的局部interface和局部home interface中不要抛出'java.rmi.RemoteException'/ Do not throw 'java.rmi.RemoteException' in a bean's local interface and local home interface [EJB.RILH-1]
4-16.构造finder方法返回类型为primary key或一个primary key集合/ Make finder methods' return type the primary key or a collection of primary keys [EJB.RT-1]
4-17.为SessionBeans或MessageDrivenBeans的'ejbCreate()'方法构造返回类型"void"/ Make the return type "void" for SessionBeans or MessageDrivenBeans' 'ejbCreate()' methods [EJB.RTC-1]
4-18.为'ejbPostCreate()'方法构造返回类型"void"/ Make the return type "void" for the 'ejbPostCreate()' method [EJB.RTP-1]
4-19.在Home interface中为EJB remote, home interfaces和bean类和确保包括所有business方法和'create'与'finder'方法的EJB bean遵循格式化名/ Follow the name format for EJB remote, home interfaces, and bean classes and ensure EJB bean contains all the business methods and 'create' and 'finder' methods in the Home interface [EJB.STD-1]
4-20.远程home或局部home interfaces在创建方法时抛出'javax.ejb.CreateException'/ Throw 'javax.ejb.CreateException' in create methods of remote home or local home interfaces [EJB.TCE-1]
4-21.远程home或局部home interfaces在finder方法时抛出'javax.ejb.FinderException'/ Throw 'javax.ejb.FinderException' in finder methods of remote home or local home interfaces [EJB.TFE-1]
4-22.自变量避免通过"this"引用/ Avoid passing the "this" reference as an argument [EJB.THISARG-1]
4-23.不要返回"this"/ Do not return "this" [EJB.THISRET-1]
4-24.不要访问或修改安全配置对象/ Do not access or modify security configuration objects [EJB.AMSC-2]
4-25.在'ejbLoad()'中不要调用finder方法/ Do not call finder methods in the 'ejbLoad()' [EJB.EJBLOAD-2]
4-26.在一个Bean中避免加载原生库/ Avoid loading native libraries in a Bean class [EJB.LNL-2]
4-27.在EJB组件"final"时声明所有"static"字段/ Declare all "static" fields in the EJB component "final" [EJB.NFS-2]
4-28.重新利用EJB homes/ Reuse EJB homes [EJB.RUH-2]
4-29.在任何地方避免开始,停止或管理线程/ Avoid starting, stopping, or managing threads in any way [EJB.THREAD-2]
4-30.使用Session外观去控制访问实体beans/ Use a Session Facade to manage access to entity beans [EJB.USF-2]
4-31.在EJB类中不要使用Servlet代码/ Do not use Servlet code in EJB classes [EJB.ABCS-3]
4-32.在java swing或ervlet类中不要使用EJB代码/ Do not use EJB code in java swing or servlet classes [EJB.ADCB-3]
4-33.避免过多的inter-entity bean通讯/ Avoid excessive inter-entity bean communication [EJB.AIEBC-3]
4-34.在EJB类内不要使用JDBC代码/ Do not use JDBC code inside of EJB classes [EJB.AJDBC-3]
4-35.在session beans和entity beans间避免一对一的映射/ Avoid one-to-one mapping between session beans and entity beans [EJB.AOTO-3]
4-36.可再利用的高速缓存JNDI资源将减少使用高代价的运算/ Cache reusable JNDI resources to minimize the use of expensive operations [EJB.UCIC-3]
4-37.fine-grained对象不要使用Entity Beans/ Do not use Entity Beans as fine-grained objects [EJB.ABFG-4]
4-38.使用有价值对象减少对服务器的调用/ Use value Objects to reduce the granularity of calls to the server [EJB.UVO-4]
 
5. Exceptions [EXCEPT]
5-1.所有字段中用户定义的'Exception'声明为"final"/ Declare all fields of user-defined 'Exception' as "final" [EXCEPT.IMMEX-3]
5-2.不要捕获'java.lang.Error'对象/ Do not catch the 'java.lang.Error' object [EXCEPT.NCERR-3]
5-3.不要捕获'NullPointerException'/ Do not catch 'NullPointerException' [EXCEPT.NCNPE-3]
5-4.不要抛出'java.lang.Error'对象/ Do not throw the 'java.lang.Error' object [EXCEPT.NTERR-3]
5-5.在控制流的语句中不要滥用异常/ Do not abuse exceptions as flow control statements [EXCEPT.AEFC-4]
5-6.不要抛出'NullPointerException'/ Do not throw 'NullPointerException' [EXCEPT.NTNPE-5]
 
6. Formatting [FORMAT]
6-1.每行书写一个语句/ Write one statement per line [FORMAT.OSPL-1]
6-2.强制在主要的模块间执行数个空行/ Enforce number of blank line(s) between major sections [FORMAT.U2BL-1]
6-3.强制缩进执行数个空格/ Enforce number of space(s) for indentation [FORMAT.IND-2]
6-4.限制每行的最大长度/ Limit the maximum length of a line [FORMAT.LL-2]
6-5.每个源文件提供一个正确的文件标题/ Provide a correct file header comment for each source file [FORMAT.MCH-2]
6-6.条件表达式采用首选格式化/ Use the preferred formatting for conditional expressions [FORMAT.TE-2]
6-7.使用'()'分隔复杂的表达式/ Use '()' to separate complex expressions [FORMAT.APAREN-3]
6-8.在独有的行放置大括号/ Place a closing brace on its own line [FORMAT.CBRACE-3]
6-9.类型分配后放置一个单独的空格符号或否/ Place a single space character or no space character after type casting [FORMAT.CMS-3]
6-10.用空格代替'Tabs'/ Use spaces instead of 'Tabs' [FORMAT.DUT-3]
6-11.以'[]'括号声明arrays在队列类型后和变量名前/ Declare arrays with '[]' brackets after the array type and before the variable name(s) [FORMAT.IAD-3]
6-12.在一个方法名和打开的"("圆括号间放置一个单独的空格字符或否/ Place a single space character or no space character between a method name and the opening "(" parenthesis [FORMAT.MSP-3]
6-13.不要在'{'打开括号相同的行放置语句/ Do not place statements on the same line as the '{' opening brace [FORMAT.NSAB-3]
6-14.强制在所有逗号后执行数个空格字符/ Enforce number of space character(s) after every comma [FORMAT.SAC-3]
6-15.强制在赋值算法每一边执行数个空格字符/ Enforce number of space character(s) on each side of an assignment operator [FORMAT.SAOP-3]
6-16.强制在条件运算的打开圆括号"("后执行数个空格字符/ Enforce number of space character(s) after the opening parenthesis "(" of a conditional statement [FORMAT.SAP-3]
6-17.强制在所有分号后执行数个空格字符/ Enforce number of space character(s) after every semicolon [FORMAT.SAS-3]
6-18.强制在一个前缀一元操作和操他的作数间执行数个空格字符/ Enforce number of space character(s) between a prefixed unary operator and its operand [FORMAT.SAUOP-3]
6-19.强制在位运算每一边执行数个空格字符/ Enforce number of space character(s) on each side of a bitwise operator [FORMAT.SBOP-3]
6-20.强制在一个后缀一元操作和操他的作数间执行数个空格字符/Enforce number of space character(s) between a postfixed unary operator and its operand [FORMAT.SBUOP-3]
6-21.强制在条件算法"?"前和后执行数个空格字符/ Enforce number of space character(s) before and after the "?" conditional operator [FORMAT.SCOP-3]
6-22.强制在逻辑运算每一边执行数个空格字符/ Enforce number of space character(s) on each side of a logical operator [FORMAT.SLOP-3]
6-23.强制在关系运算每一边执行数个空格字符/ Enforce number of space character(s) on each side of a relational operator [FORMAT.SROP-3]
6-24.避免不必要的圆括号/ Avoid unnecessary parentheses [FORMAT.UP-3]
6-25.强制在类型声明前执行数个空行/ Enforce number of blank line(s) before type declarations [FORMAT.BLCD-4]
6-26.强制执行数个空行去分隔不同的"imports"包/ Enforce number of blank line(s) to separate "imports" from different packages [FORMAT.BLSIM-4]
6-27.强制执行'{'大括号的位置/ Enforce the position of '{' brace [FORMAT.FCB-4]
6-28.放置跟第一个类型有相同文件名的类型/ Place the type that has the same name as the file as the first type [FORMAT.FCN-4]
6-29.强制定制注释和修改人/ Enforce the order of annotations and modifiers [FORMAT.MO-4]
6-30.确信所有文件终止于换行字符/ Make sure all files are terminated with a newline character [FORMAT.TNL-4]
6-31.不要在行末放置空个空格区字段/ Do not place empty whitespace at the end of a line [FORMAT.ATS-5]
6-32.避免使用拖长的注释/ Avoid using trailing comments [FORMAT.TC-5]
6-33.避免或强制在array初始化时使用拖长的逗号/ Avoid or enforce the use of trailing commas in array initializers [FORMAT.TCOMMA-5]
 
7. Garbage Collection [GC]
7-1.从'finalize ()'来调用'super.finalize ()'/ Call 'super.finalize ()' from 'finalize ()' [GC.FCF-1]
7-2.不要使用'finalize ()'方法去注销监听?/ Do not use 'finalize ()' methods to unregister listeners [GC.FM-1]
7-3.不要直接调用'finalize ()'/ Do not call 'finalize ()' explicitly [GC.NCF-1]
7-4.当转换原始类型为String时不要使用不必要的临时变量/ Do not use unnecessary temporaries when converting primitive types to String [GC.AUTP-2]
7-5.在'finalize()'方法的"finally"模块中调用'super.finalize()'/ Call 'super.finalize()' in the "finally" block of 'finalize()' methods [GC.IFF-2]
7-6.调用'reset ()'时在ObjectOutputStreams预防潜在的内存泄漏/ Prevent potential memory leaks in ObjectOutputStreams by calling 'reset ()' [GC.OSTM-2]
7-7.避免使用'long[]'来替代'Date[]'/ Avoid using 'Date[]', use 'long[]' instead [GC.DUD-3]
7-8.不要直接调用'System.gc()'或'Runtime.gc()'/ Do not explicitly call 'System.gc()' or 'Runtime.gc()' [GC.GC-3]
7-9.避免使用"static"的collections 或 maps;他们能超过范围的增长/ Avoid "static" collections or maps; they can grow without bounds [GC.STV-3]
7-10.重新调用'getClipBounds()'/ Reuse calls to 'getClipBounds()' [GC.GCB-5]
 
8. Global Static Analysis [GLOBAL]
8-1.尽可能声明package-private类型难以访问/ Declare package-private types as inaccessible as possible [GLOBAL.DPAC-1]
8-2.尽可能声明package-private域难以访问/ Declare package-private fields as inaccessible as possible [GLOBAL.DPAF-1]
8-3.尽可能声明package-private方法难以访问/Declare package-private methods as inaccessible as possible [GLOBAL.DPAM-1]
8-4.避免全局使用package-private类型/ Avoid globally unused package-private types [GLOBAL.UPAC-1]
8-5.避免全局使用package-private域/ Avoid globally unused package-private fields [GLOBAL.UPAF-1]
8-6.避免全局使用package-private方法/注释成分类型/ Avoid globally unused package-private methods/annotation member types [GLOBAL.UPAM-1]
8-7.避免使用"throws"语句/ Avoid unused "throws" clauses [GLOBAL.AUT-2]
8-8.如果一个package-private的"class/interface"没有子集则把他声明为"final"/ Declare a package-private "class/interface" "final" if it is not subclassed [GLOBAL.SPAC-2]
8-9.如果一个package-private的方法没有没有被覆写则把他声明为"final"/ Declare a package-private method "final" if it is not overridden [GLOBAL.SPAM-2]
8-10.在有效类中应保证正确的构造器声明/ Ensure correct constructor declarations in utility classes [GLOBAL.UCC-2]
8-11.如果方法不使用实例化类成员则使他们为"static"/ Make methods "static" if they do not use instance class members [GLOBAL.ASI-3]
8-12.声明"public/protected"类型尽可能无法访问/ Declare "public/protected" types as inaccessible as possible [GLOBAL.DPPC-4]
8-13.声明"public/protected"字段尽可能无法访问/Declare "public/protected" fields as inaccessible as possible [GLOBAL.DPPF-4]
8-14.声明"public/protected"方法尽可能无法访问/Declare "public/protected" methods as inaccessible as possible [GLOBAL.DPPM-4]
8-15.避免全局从未使用"public/protected"类型Avoid globally unused "public/protected" types [GLOBAL.UPPC-4]
8-16.避免全局从未使用"public/protected"字段/ Avoid globally unused "public/protected" fields [GLOBAL.UPPF-4]
8-17.避免全局从未使用"public/protected" 方法和注释成员类型/ Avoid globally unused "public/protected" methods/annotation member types [GLOBAL.UPPM-4]
8-18.声明一个"public/protected" "class/interface"没有子集则声明为"final"/ Declare a "public/protected" "class/interface" "final" if it is not subclassed [GLOBAL.SPPC-5]
8-19.如果一个"public/protected"方法没有被覆写则声明为"final"/ Declare a "public/protected" method "final" if it is not overridden [GLOBAL.SPPM-5]
 
9. Initialization [INIT]
9-1.在初始化期间不要使用非final "static"字段/ Do not use non-final "static" fields during the initialization [INIT.NFS-2]
9-2.使用外部初始化/不要用默认值对"static"字段初始化/ Use explicit initializations/Do not initialize "static" fields to default values [INIT.SF-2]
9-3.避免在构造器执行前或执行期间对该字段进行非初始化的读取/ Avoid uninitialized reads of fields before or during constructor execution [INIT.UIRC-2]
9-4.明确的在声明语句中初始化所有局部变量/ Initialize all local variables explicitly at the declaration statement [INIT.LV-3]
9-5.不要同非"final" "static"变量一起初始化"static" "final"变量/ Do not initialize "static" "final" variables with non "final" "static" variables [INIT.SFA-3]
9-6.在所有"static final"字段被赋值前不要使用"static"初始化方式创建一个当前类的实例/ Do not use a "static" initializer that creates an instance of the current class before all "static final" fields are assigned [INIT.SICUI-3]
9-7.在构造器中明确的初始化所有字段/ Explicitly initialize all fields in a constructor [INIT.CSI-4]
9-8.不要对字段进行环状的初始化方式/ Do not use initialization circularities for fields [INIT.IC-4]
 
10. Internationalization [INTER]
10-1.当调用'String'转换方法时提供'Locale'自变量/ Provide 'Locale' argument when invoking 'String' conversion methods [INTER.CCL-3]
10-2.在国际化环境中隔离可翻译的文本资源包/ Isolate translatable text in resource bundles in an Internationalized environment [INTER.ITT-3]
10-3.当实例化'SimpleDateFormat'对象时提供'Locale'自变量/ Provide 'Locale' argument when instantiating 'SimpleDateFormat' objects [INTER.SDFL-3]
10-4.在国际化环境中不要使用单一的逻辑操作字符/ Do not use single characters with logic operators in an Internationalized environment [INTER.CLO-4]
10-5.在国际化环境中不要使用String串/ Do not use String concatenation in an Internationalized environment [INTER.COS-4]
10-6.在国际化环境中对日期变量不要调用'toString ()'/ Do not call 'toString ()' on Date variables in an Internationalized environment [INTER.DTS-4]
10-7.在国际化环境中对常量使用单一字面意义的字符/ Use single character literals in constants in an Internationalized environment [INTER.NCL-4]
10-8.在国际化环境中对数字量不要调用'toString ()'/ Do not call 'toString ()' on numeric variables in an Internationalized environment [INTER.NTS-4]
10-9.在国际化环境中不要调用'String.compareTo ()'/ Do not call 'String.compareTo ()' in an Internationalized environment [INTER.SCT-4]
10-10.在国际化环境中不要调用'String.equals ()'/ Do not call 'String.equals ()' in an Internationalized environment [INTER.SE-4]
10-11.在国际化环境中不要使用'StringTokenizer'/ Do not use 'StringTokenizer' in an Internationalized environment [INTER.ST-4]
10-12.在国际化环境中不要调用'Time.toString ()'/ Do not call 'Time.toString ()' in an Internationalized environment [INTER.TTS-4]
 
11. Java 2 Micro Edition [J2ME](微型平台暂时不翻译)
Do not use anonymous classes as interface implementors [J2ME.ACII-1]
Do not use an array length in a loop condition expression [J2ME.ARLL-1]
Avoid constant initializations of primitive arrays that exceed a certain size [J2ME.CIPA-1]
Avoid classes that are subclassed only once and are not publicly used [J2ME.CSOO-1]
Do not access a field excessively [J2ME.EAOF-1]
Ensure methods use return parameters instead of returning new objects [J2ME.EURP-1]
Catch 'OutOfMemoryError' for large array allocations [J2ME.OOME-1]
 
 
12. Javadoc Comments [JAVADOC]
12-1.避免不使用Javadoc标记/ Avoid unused Javadoc tags [JAVADOC.DPMT-1]
12-2.在方法的Javadoc注释中使用'@return' Javadoc标记/ Use the '@return' Javadoc tag in method Javadoc comments [JAVADOC.MRDC-1]
12-3.对方法的每个参数使用'@param' Javadoc标记/ Use the '@param' Javadoc tag for each parameter of methods [JAVADOC.PARAM-1]
12-4.为类型提供Javadoc注释和描述/ Provide Javadoc comments and descriptions for types [JAVADOC.PJDC-1]
12-5.为字段提供Javadoc注释和描述/ Provide Javadoc comments and descriptions for fields [JAVADOC.PJDF-1]
12-6.为方法提供Javadoc注释和描述/Provide Javadoc comments and descriptions for methods [JAVADOC.PJDM-1]
12-7.在"synchronized"的方法和块中使用'@concurrency' Javadoc标记/ Use the '@concurrency' Javadoc tag on "synchronized" methods and blocks [JAVADOC.SMJT-1]
12-8.在方法中使用'@throws'或'@exception' Javadoc标记/ Use the '@throws' or '@exception' Javadoc tag in methods [JAVADOC.THROW-1]
12-9.在"void"方法中避免使用'@return' Javadoc标记/ Avoid using the '@return' Javadoc tag on "void" methods [JAVADOC.VMCR-1]
12-10.在Javadoc注释的声明中使用'@author' Javadoc标记/ Use the '@author' Javadoc tag in declaration Javadoc comments [JAVADOC.MAJDT-3]
12-11.在Javadoc注释的类型中使用'@version'标记/ Use the '@version' tag in type Javadoc comments [JAVADOC.MVJDT-3]
12-12.适当的定义Javadoc标记/ Order Javadoc tags appropriately [JAVADOC.ORDER-3]
12-13.为'toString ()'方法提供Javadoc注释/ Provide Javadoc comment for 'toString ()' method [JAVADOC.TSMJT-3]
12-14.避免没有在Javadoc注释中使用过的不支持的'@'标记和其他标记/ Avoid unsupported '@' tags and other tags that should not be used in Javadoc comments [JAVADOC.BT-4]
12-15.不要在Javadoc注释和描述中插入非Javadoc注释/ Do not insert non-Javadoc comments between Javadoc comments and declarations [JAVADOC.JNJD-5]
12-16.强制控制使用Javadoc注释的行数/ Enforce restraint on number of lines used for Javadoc comments [JAVADOC.SINGLE-5]
 
13. Java Database Connectivity [JDBC]
13-1.在"finally"块中关闭JDBC连接/ Close JDBC connections in "finally" blocks [JDBC.CDBC-1]
13-2.为JDBC连接重新使用数据源/ Reuse data sources for JDBC connections [JDBC.DSLV-2]
13-3.在"finally"块中关闭JDBC资源/ Close JDBC resources in "finally" blocks [JDBC.RRWD-2]
13-4.使用javax.sql.DataSource去获取数据库连接/ Use javax.sql.DataSource to get the database connection [JDBC.UDS-4]
 
14. JavaServer Pages [JSP]
14-1.不要有超过一个的同样名字的字段/ Do not have more than one field with the same name [JSP.DUPF-1]
14-2.不要有超过一个的同样名字的局部变量/Do not have more than one local variable with the same name [JSP.DUPLV-1]
14-3.不要有超过一个的同样签名的方法/Do not have more than one method with the same signature [JSP.DUPM-1]
14-4.在include指令中确保不出现无限循环/ Ensure infinite loops do not occur in include directives [JSP.INF-1]
14-5.确保保留的局部变量名没有使用/ Ensure that reserved local variable names are not used [JSP.URLV-1]
14-6.为每个JSP文件提供一个标题注释/ Provide a header comment for each JSP file [JSP.JSPH-2]
 
15. JavaServer Page Metrics [JMETRICS]
15-1.在JSP文件中遵循限定的Java行数/ Follow limit for number of Java lines in JSP file [JMETRICS.NJL-2]
15-2.在JSP文件中遵循限定的字段数/ Follow limit for number of fields in a JSP file [JMETRICS.NOF-2]
15-3.在JSP文件中遵循限定的JSP声明数/ Follow limit for number of JSP declarations in JSP file [JMETRICS.NOJD-2]
15-4.在JSP文件中遵循限定的JSP脚本数/ Follow limit for number of JSP scriptlets in a JSP file [JMETRICS.NOJS-2]
15-5.在JSP文件中遵循限定的方法数/ Follow limit for number of methods in a JSP file [JMETRICS.NOM-2]
15-6.在JSP文件中遵循限定的package-private字段数/ Follow limit for number of package-private fields in a JSP file [JMETRICS.NOPKGF-2]
15-7.在JSP文件中遵循限定的package-private方法数/Follow limit for number of package-private methods in a JSP file [JMETRICS.NOPKGM-2]
15-8.在JSP文件中遵循限定的"private"字段数/Follow limit for number of "private" fields in JSP file [JMETRICS.NOPRIF-2]
15-9.在JSP文件中遵循限定的"private"方法数/Follow limit for number of "private" methods in a JSP file [JMETRICS.NOPRIM-2]
15-10.在JSP文件中遵循限定的"protected"字段数/Follow limit for number of "protected" fields in a JSP file [JMETRICS.NOPROF-2]
15-11.在JSP文件中遵循限定的"protected"方法数/Follow limit for number of "protected" methods in a JSP file [JMETRICS.NOPROM-2]
15-12.在JSP文件中遵循限定的"public"字段数/Follow limit for number of "public" fields in a JSP file [JMETRICS.NOPUBF-2]
15-13.在JSP文件中遵循限定的"public"方法数/Follow limit for number of "public" methods in a JSP file [JMETRICS.NOPUBM-2]
15-14.Java行数遵循限定的百分比/ Follow limit for percentage of Java lines (%) [JMETRICS.PJL-2]
 
16. JUnit Test Case [JUNIT]
16-1.构造'suite()'方法为"public"和"static"/ Make 'suite()' methods "public" and "static" [JUNIT.SUITE-1]
16-2.确定所有方法都有至少一个JUnit测试方法/ Make sure all methods have at least one JUnit test method [JUNIT.TEST-1]
16-3.不要使用构造器去装配测试用例/ Do not use the constructor to set up test cases [JUNIT.OSIC-2]
16-4.确保JUnit测试用例包含断言方法/ Ensure JUnit test cases include assertion methods [JUNIT.SIA-2]
16-5.在JUnit断言中包含一个消息串/ Include a message string in JUnit assertions [JUNIT.ASSERT-3]
16-6.在'setUp()'中调用'super.setUp()'和在'tearDown()'中调用'super.tearDown()'/ Call 'super.setUp()' in 'setUp()' and 'super.tearDown()' in 'tearDown()' [JUNIT.CSUPER-3]
16-7.强制一个条件失败使用fail()方法代替使用assertTrue(false)或assertFalse(true)方法/ Use the fail() method instead of forcing a failed condition using the assertTrue(false) or assertFalse(true) method [JUNIT.FAIL-3]
16-8.覆写'setUp ()'方法/ Override the 'setUp ()' method [JUNIT.OSUM-3]
16-9.覆写'tearDown ()'方法/ Override the 'tearDown ()' method [JUNIT.OTDM-3]
16-10.为JUnit测试方法包含一个适当的Javadoc标记/ Include an appropriate Javadoc tag in the Javadoc for JUnit test methods [JUNIT.UPJT-3]
16-11.单元测试对不要使用困难编码的数据/ Do not hard code the location to data used by a unit test [JUNIT.AHLOD-4]
16-12.确保JUnit类有一个main()允许他们独立执行/ Ensure that JUnit classes have a main() allowing them to be executed in isolation [JUNIT.MAIN-4]
16-13.类测试应放置每个测试类在相同的位置/ Place each test class in the same location as the class that it tests [JUNIT.DIR-5]
 
17. Class Metrics [METRICS]
17-1.在一个"class"或"interface"中遵循限定的注释行数/ Follow the limit for number of comment lines in a "class" or "interface" [METRICS.CCNL-2]
17-2.遵循限定的"class"或"interface"继承层次/ Follow the limit for "class" or "interface" inheritence level [METRICS.CIHL-2]
17-3.在一个方法中遵循限定的注释行数/ Follow the limit for number of comment lines in a method [METRICS.CNLM-2]
17-4.在一个"class"或"interface"中遵循限定的语句行数/ Follow the limit for number of statment lines in a "class" or "interface" [METRICS.CSNL-2]
17-5.在一个"class"或"interface"中遵循限定的行数/Follow the limit for number of lines in a "class" or "interface" [METRICS.CTNL-2]
17-6.遵循限定的字段数/ Follow the limit for number of fields [METRICS.NOF-2]
17-7.遵循限定的方法数/Follow the limit for number of methods [METRICS.NOM-2]
17-8.遵循限定的package-private字段数/Follow the limit for number of package-private fields [METRICS.NPKGF-2]
17-9.遵循限定的package-private方法数/Follow the limit for number of package-private methods [METRICS.NPKGM-2]
17-10.遵循限定的"private"字段数/Follow the limit for number of "private" fields [METRICS.NPRIF-2]
17-11.遵循限定的"private"方法数/Follow the limit for number of "private" methods [METRICS.NPRIM-2]
17-12.遵循限定的"protected"字段数/Follow the limit for number of "protected" fields [METRICS.NPROF-2]
17-13.遵循限定的"protected"方法数/Follow the limit for number of "protected" methods [METRICS.NPROM-2]
17-14.遵循限定的"public"字段数/Follow the limit for number of "public" fields [METRICS.NPUBF-2]
17-15.遵循限定的"public"方法数/Follow the limit for number of "public" methods [METRICS.NPUBM-2]
17-16.遵循限定的Javadoc注释百分比/ Follow the limit for percentage of Javadoc comments (%) [METRICS.PJDC-2]
17-17.在一个方法中遵循限定的语句行数/ Follow the limit for number of statement lines in a method [METRICS.SNLM-2]
17-18.在一个方法中遵循限定的语句数/Follow the limit for number of statements in a method [METRICS.STMT-2]
17-19.遵循限定的迭代复杂/ Follow the limit for Cyclomatic Complexity [METRICS.TCC-2]
17-20.在一个方法中遵循限定的行数/ Follow the limit for number of lines in a method [METRICS.TNLM-2]
17-21.遵循限定的方法调用数/ Follow the limit for number of method calls [METRICS.TNMC-2]
17-22.遵循限定的参数/ Follow the limit for number of parameters [METRICS.TNOP-2]
17-23.遵循限定的"return"语句数/ Follow the limit for number of "return" statements [METRICS.TRET-2]
17-24.在一个匿名类中遵循限定的行数/ Follow the limit for number of lines in anonymous class [METRICS.ACTNL-3]
17-25.遵循限定的每个switch-case语句/Follow the limit for statements of each switch-case [METRICS.CASE-3]
17-26.遵循限定的嵌套-if层次/ Follow the limit for nested-if levels [METRICS.DIF-3]
17-27.遵循限定的嵌套-try层次/ Follow the limit for nested-try levels [METRICS.DTRY-3]
17-28.在一个文件中遵循限定的import数/ Follow the limit for number of import statements in a file [METRICS.IMPT-3]
17-29.在一个方法声明中遵循限定的抛出声明数/ Follow the limit for the number of throws declarations in a method declaration [METRICS.TNOT-3]
 
18. Miscellaneous [MISC]
18-1.不使用一个对象去访问"static"字段或方法/ Do not use an object to access "static" fields or methods [MISC.AUO-1]
18-2.在'clone ()'方法中不要使用构造器/ Do not use constructors in the 'clone ()' method [MISC.CLNC-1]
18-3.在所有'clone ()'方法中调用'super.clone ()'/ Call 'super.clone ()' in all 'clone ()' methods [MISC.CLONE-1]
18-4.不要使用不赞成的APIs/ Do not use deprecated APIs [MISC.DPRAPI-1]
18-5.为所有'Serializable'类创建一个'serialVersionUID'/ Create a 'serialVersionUID' for all 'Serializable' classes [MISC.DUID-1]
18-6.声明"private"的常量字段为"final"/ Declare "private" constant fields "final" [MISC.FF-1]
18-7.不要使方法的局部变量和参数与类字段同名/ Do not give method local variables and parameters the same name as class fields [MISC.HMF-1]
18-8.以一个条件和增量语句声明"for"循环/ Declare "for" loops with a condition and an increment statement [MISC.PCIF-1]
18-9.重声明一个类仅用"abstract"方法和"static final"字段做为"interface"/ Redeclare a class with only "abstract" methods and "static final" fields as an "interface" [MISC.ASFI-2]
18-10.在一个非"public"类内不要声明构造器为"public"/ Do not declare "public" constructors in non-public classes [MISC.PCTOR-2]
18-11.仅仅在块的开始处添加声明/ Put declarations only at the beginning of blocks [MISC.PDBB-2]
18-12.避免使用"public static final"队列字段/ Avoid using "public static final" array fields [MISC.PSFA-2]
18-13.String分解用'StringTokenizer'代替'indexOf ()'或'substring ()'/ Use 'StringTokenizer' instead of 'indexOf ()' or 'substring ()' for String parsing [MISC.UST-2]
18-14.避免使用被依赖的包或类型/ Avoid using certain packages or types [MISC.APT-3]
18-15.返回空队列来代替"null"/ Return zero-length arrays instead of "null" [MISC.ARN-3]
18-16.为条件语句提供一个'{}'块/ Provide a '{}' block for conditional statements [MISC.BLK-3]
18-17.在"abstract"类内不要声明构造器为"public"/ Do not declare "public" constructors in "abstract" classes [MISC.NPAC-3]
18-18.确保"public"类有至少一个"public"或"protected"成员/ Ensure "public" classes have at least one "public" or "protected" member [MISC.PMPC-3]
18-19.如果需要精确的回复不要使用"float"和"double"/ Do not use "float" and "double" if exact answers are required [MISC.UBD-3]
18-20.不要使用 "break"和/或"continue"语句/ Do not use "break" and/or "continue" statements [MISC.CONTINUE-4]
18-21.不要从构造器调用非"final",非"static"和非"private"方法/ Do not call non-"final", non-"static" and non-"private" methods from constructors [MISC.CTOR-4]
18-22.在变量使用后尽可能声明变量终结/ Declare variables as close as possible to where they are used [MISC.DVCU-4]
18-23.声明局部变量为常量"final"/ Declare constant local variables "final" [MISC.FLV-4]
18-24.不要使用太多非"final" "static"字段/ Do not use too many non-"final" "static" fields [MISC.MSF-4]
18-25.避免string字面意义除了常量声明和调用System.out or System.err's 'print' or 'println'方法/ Avoid string literals except in constant declarations and calls to System.out or System.err's 'print' or 'println' methods [MISC.SL-4]
18-26.确保代码不包含TODO注释/ Ensure that code does not contain TODO comments [MISC.TODO-4]
18-27.不要对"Throwable"对象调用'printStackTrace()'方法/ Do not call the 'printStackTrace()' method of "Throwable" objects [MISC.ACPST-5]
18-28.不要对方法参数进行赋值/ Do not make assignments to method parameters [MISC.AFP-5]
18-29.避免使用"do-while"语句/ Avoid using "do-while" statements [MISC.DOWHILE-5]
18-30.使用"for"循环代替"while"循环/ Use "for" loops instead of "while" loops [MISC.PFL-5]
18-31.避免在单一个类中重复出现字面意义的string/ Avoid repeated string literals in a single class [MISC.RSL-5]
18-32.避免系统'print()'或'println()'的语句/ Avoid System 'print()' or 'println()' statements [MISC.SIO-5]
 
19. Naming Conventions [NAMING]
19-1.为getter方法预先以'get'命名/ Prepend 'get' to the names of getter methods [NAMING.GETA-1]
19-2.仅仅使用'is...'命名方法返回一个"boolean"/ Use 'is...' only for naming methods that return a "boolean" [NAMING.IRB-1]
19-3.不要使用一个Sun保留的包名/ Do not use a package name that is reserved by Sun [NAMING.RPKG-1]
19-4.在一个"interface"中使用大写字母命名所有字段/ Use all uppercase letters for the names of fields in an "interface" [NAMING.IFV-2]
19-5.为类使用一个约定的命名/ Use a naming convention for classes [NAMING.NCL-2]
19-6.为异常使用一个约定的命名/Use a naming convention for exceptions [NAMING.NE-2]
19-7.为非"static"字段使用一个约定的命名/Use a naming convention for non-"static" fields [NAMING.NIF-2]
19-8.为接口使用一个约定的命名/Use a naming convention for interfaces [NAMING.NITF-2]
19-9.为局部变量常使用一个约定的命名/Use a naming convention for local variables [NAMING.NLV-2]
19-10.为非"static"方法使用一个约定的命名/Use a naming convention for non-"static" methods [NAMING.NM-2]
19-11.为方法参数使用一个约定的命名/Use a naming convention for method parameters [NAMING.NMP-2]
19-12.为非"final" "static"字段使用一个约定的命名/Use a naming convention for non-"final" "static" fields [NAMING.NSF-2]
19-13.为"static"方法使用一个约定的命名/Use a naming convention for "static" methods [NAMING.NSM-2]
19-14.为"package"名使用一个约定的命名/Use a naming convention for "package" names [NAMING.PKG-2]
19-15.为setter方法预先以'set'命名/ Prepend 'set' to the names of setter methods [NAMING.SETA-2]
19-16.在"final" "static"字段命名中不要使用小写字母/ Do not use lowercase letters in "final" "static" field names [NAMING.USF-2]
19-17.预先以'is, can, has, have, are, was'来命名"boolean"getter方法/ Prepend 'is, can, has, have, are, was' to the names of "boolean" getter methods [NAMING.GETB-3]
19-18.避免类或接口命名超过14个字符的长度/ Avoid class or interface names which are more than 14 characters long [NAMING.LCIN-4]
19-19.为自变量使用匈牙利法则/ Use Hungarian notation for variables [NAMING.UHN-4]
19-20.使用常规的自变量名/ Use conventional variable names [NAMING.CVN-5]
19-21.为"abstract"类使用一个常规的命名/ Use a naming convention for "abstract" classes [NAMING.NACL-5]
19-22.为"final"局部自变量使用一个常规的命名/ Use a naming convention for "final" local variables [NAMING.NFL-5]
 
20. Object Oriented Programming [OOP]
20-1.避免"public"/"protected"/package-private字段/ Avoid "public"/"protected"/package-private fields [OOP.AF-1]
20-2.不要隐藏继承字段/ Do not hide inherited fields [OOP.AHF-1]
20-3.不要隐藏继承"static"成员方法/ Do not hide inherited "static" member methods [OOP.AHSM-2]
20-4.避免超过两层嵌套的匿名类/ Avoid more than two levels of nested inner classes [OOP.LEVEL-2]
20-5.不要覆写一个实例化的"private"类/ Do not override an instance "private" method [OOP.OPM-2]
20-6.在outer类中不要隐藏继承字段/ Do not hide fields in outer classes [OOP.HIF-3]
20-7.实现接口为非平凡或"abstract"/ Implement interfaces non-trivially or "abstract" [OOP.IIN-5]
 
21.  Optimization [OPT]
21-1.当创建String对象去支持字面意义string时不要使用"new"关键字/ Do not use the "new" keyword when creating String objects to hold string literals [OPT.ACDO-1]
21-2.在"finally"块中关闭输入和输出资源/ Close input and output resources in "finally" blocks [OPT.CIO-1]
21-3.避免不必要的"instanceof"赋值/ Avoid unnecessary "instanceof" evaluations [OPT.UISO-1]
21-4.避免不必要的强制类型转换/ Avoid unnecessary casting [OPT.UNC-1]
21-5.不要通过新对象实例化来获取'Class'对象/ Do not get the 'Class' object through new object instantiation [OPT.AGC-2]
21-6.使用'System.arraycopy ()'代替使用一个循环来拷贝arrays/ Use 'System.arraycopy ()' instead of using a loop to copy arrays [OPT.IRB-2]
21-7.对非常量strings使用'StringBuffer'来代替'String'/ Use 'StringBuffer' instead of 'String' for non-constant strings [OPT.USB-2]
21-8.对非常量strings使用'String'来代替'StringBuffer'/ Use 'String' instead of 'StringBuffer' for constant strings [OPT.USC-2]
21-9.使用简短的赋值运算/ Use abbreviated assignment operators [OPT.AAS-3]
21-10.不要使用'Boolean'对象实例化/ Do not use 'Boolean' object instantiation [OPT.BOOLEAN-3]
21-11.返回单一化"boolean"/ Simplify "boolean" returns [OPT.BR-3]
21-12.在条件循环语句中不要调用方法/ Do not call methods in loop condition statements [OPT.CEL-3]
21-13.只有一个方法访问时不要使用"private"字段;改变他成为一个局部变量/ Do not use a "private" field that is accessed in only one method; change it to a local variable [OPT.CTLV-3]
21-14.定义初始的'ArrayList', 'HashMap', 'HashSet', 'Hashtable', 'Vector' and 'WeakHashMap'计算效率/ Define initial capacities for 'ArrayList', 'HashMap', 'HashSet', 'Hashtable', 'Vector' and 'WeakHashMap' [OPT.DIC-3]
21-15.避免对象实例化因为可能需要产生访问/ Avoid object instantiations that might need generated accessors [OPT.ICGA-3]
21-16.不要在一个循环体中实例化变量/ Do not instantiate variables in a loop body [OPT.LOOP-3]
21-17.同一个已知的编译时间值"static"一样声明"final"字段/ Declare "final" fields with a known compile time value as "static" [OPT.NSF-3]
21-18.对于一个字符的比较使用'charAt()'来代替'startsWith()'/ Use 'charAt()' instead of 'startsWith()' for one character comparisons [OPT.PCTS-3]
21-19.指定一个初始的'StringBuffer'容量/ Specify an initial 'StringBuffer' capacity [OPT.SB-3]
21-20.对于单一字符string串联使用单一引用代替双重引用/ Use single quotes instead of double quotes for single character string concatenation [OPT.STR-3]
21-21.不要在'java.lang.String'对象之上调用'toString()'/ Do not invoke 'toString()' on 'java.lang.String' object [OPT.STS-3]
21-22.不要在一个循环中调用"synchronized"方法/ Do not call a "synchronized" method in a loop [OPT.SYN-3]
21-23.在循环之外放置"try/catch/finally"块/ Place "try/catch/finally" blocks outside of loops [OPT.TRY-3]
21-24.不以"true"比较布尔变量/ Do not compare boolean variables with "true" [OPT.UEQ-3]
21-25.避免使用不可靠的非短路的逻辑/ Avoid questionable uses of non-short-circuit logic [OPT.USCL-3]
21-26.只要有可能就使用'stack'变量/ Use 'stack' variables whenever possible [OPT.USV-3]
21-27.为了实例化字段为"final"而构造访问的方法 Make accessor methods for instance fields "final" [OPT.MAF-4]
21-28.使用右位移运算来除去2的幂次方/ Use the right shift operator for division by powers of 2 [OPT.SDIV-4]
21-29.如果可能的话声明成员类为"static"/ Declare member classes "static" if possible [OPT.SI-4]
21-30.使用左位移运算来乘上2的幂次方/ Use the left shift operator for multiplication by powers of 2 [OPT.SMUL-4]
21-31.仅仅在接口中使用"instanceof"/ Use "instanceof" only on interfaces [OPT.INSOF-5]
21-32.在'toArray()'中使用集合大小作为array目标/ Use collection size for target array in 'toArray()' [OPT.TOARRAY-5]
 
22. Possible Bugs [PB]
22-1.避免不对齐的"else"语句/ Avoid dangling "else" statements [PB.ADE-1]
22-2.避免"try", "catch"和"finally"块体为空/ Avoid "try", "catch" and "finally" blocks with empty bodies [PB.AECB-1]
22-3.如果其他"return"在try-catch块内则避免"return"里有"finally"块/ Avoid "return"s inside "finally" blocks if there are other "return"s inside the try-catch block [PB.ARCF-1]
22-4.避免在一个"if"条件里赋值/ Avoid assignment within an "if" condition [PB.ASI-1]
22-5.避免条件表达式总是求一个常量的值/ Avoid conditional expressions that always evaluate to a constant value [PB.CC-1]
22-6.不要在'ComponentListener.componentResized()'中调用'setSize()'/ Do not call 'setSize()' in 'ComponentListener.componentResized()' [PB.DNCSS-1]
22-7.避免控制语句块体为空/ Avoid control statements with empty bodies [PB.EB-1]
22-8.确保IllegalArgumentException信息匹配代码逻辑/ Make sure the IllegalArgumentException message matches the code logic [PB.IIAE-1]
22-9.仅仅使用'main()'方法名作为方法的入口点/ Use the method name 'main()' only for the entry point method [PB.MAIN-1]
22-10.不要让类中的非构造方法同名/ Do not give non-constructor methods the same name as the class [PB.NAMING-1]
22-11.不要直接或间接的定义'Error'和'Throwable'的子集/ Do not define direct or indirect subclasses of 'Error' and 'Throwable' [PB.NDC-1]
22-12.避免超出范围的"char"比较/ Avoid out of range "char" comparisons [PB.OOR-1]
22-13.确保get/set方法访问了正确的变量/ Ensure get/set methods are accessing the correct variables [PB.SG-1]
22-14.确保"switch"语句没有包含排版/ Ensure "switch" statements do not contain typos [PB.TLS-1]
22-15.避免不能达到的"else if"和"else"状况/ Avoid unreachable "else if" and "else" cases [PB.UIF-1]
22-16.确保自变量转到Java包装类别没有包含排版/ Ensure that arguments passed to Java wrapper classes do not contain typos [PB.WT-1]
22-17.对于'java.util.Properties'对象避免'put, 'putAll'和'get'方法/ Avoid 'put, 'putAll' and 'get' methods of 'java.util.Properties' objects [PB.APPG-2]
22-18.对最低精度不要粗略的强制转换数据类型/ Do not cast primitive data types to lower precision [PB.CLP-2]
22-19.不要比较浮点类型/ Do not compare floating point types [PB.DCF-2]
22-20.对于总是返回false不要调用'equals()'方法/ Do not call 'equals()' methods that always return false [PB.EQUS-2]
22-21.不要在一个"for"循环体中给循环控制变量赋值/ Do not assign loop control variables in the body of a "for" loop [PB.FLVA-2]
22-22.确保覆写的方法名没有排版/ Ensure the overriding method name does not have a typo [PB.IMO-2]
22-23.在能够序列化的类中为'readResolve ()'和'writeReplace ()'方法分配"protected"的可见度/ Assign "protected" accessibility to 'readResolve ()' and 'writeReplace ()' methods in serializable classes [PB.MASP-2]
22-24.不要对'finalize()'方法负载/ Do not overload the 'finalize()' method [PB.OF-2]
22-25.确保方法自变量能够序列化/ Ensure method arguments are serializable [PB.ONS-2]
22-26.为每个"switch"语句提供"default:"/ Provide "default:" for each "switch" statement [PB.PDS-2]
22-27.避免字段和/或局部变量的自我赋值/初始化/ Avoid self assignments/initializations to fields and/or local variables [PB.SAFL-2]
22-28.避免空语句/ Avoid empty statements [PB.AES-3]
22-29.避免在"finally"块中有"throw"语句/ Avoid "throw" statements in "finally" blocks [PB.ATSF-3]
22-30.避免从未使用的循环变量/ Avoid unused loop variables [PB.AULV-3]
22-31.避免错乱的构造器自变量赋值/ Avoid confusing assignments to constructor arguments [PB.AWP-3]
22-32.不要使用"+"字符连续运算去连接数字;仅仅使用他来对数字相加/ Do not use the "+" string concatenation operator to concatenate numbers; use it only to add numbers [PB.DCP-3]
22-33.避免空的类/ Avoid empty classes [PB.EC-3]
22-34.在'equals()'方法执行时使用'getClass()'/ Use 'getClass()' in the 'equals()' method implementation [PB.EQL-3]
22-35.在'equals()'方法执行内部使用'instanceof'/ Use 'instanceof' within an 'equals()' method implementation [PB.EQL2-3]
22-36.确保因为不同的参数类型覆写的方法没有是非预料的协变/ Ensure overriding methods are not unintended covariants due to parameter type differences [PB.IMC-3]
22-37.确保"static" "final"字段是恒量的/ Ensure "static" "final" fields are immutable [PB.IMM-3]
22-38.不要调用'String.equals ("literal")' or 'String.equalsIgnoreCase("literal")'/ Do not call 'String.equals ("literal")' or 'String.equalsIgnoreCase("literal")' [PB.ISEM-3]
22-39.不要在多个嵌套"for"循环语句上对同个自变量增量或减量/ Do not increment or decrement on the same variable over multiple nested "for" loop statements [PB.JI-3]
22-40.避免类不可访问/ Avoid classes that are not accessible [PB.NACC-3]
22-41.不要定义'RuntimeException'的直接或间接子集/ Do not define direct or indirect subclasses of 'RuntimeException' [PB.NXRE-3]
22-42.确保正好一个类型有同样的名与文件名/ Ensure that exactly one type has the same name as the file name [PB.OCSF-3]
22-43.在"switch"语句的最后情形放置"default"/ Place "default" as the last case of the "switch" statement [PB.PDCL-3]
22-44.在一个"catch"子句中不要重抛出一个异常/ Do not rethrow an exception in a "catch" clause [PB.RTE-3]
22-45.一个错误的"case"不要使用一个"switch"语句/ Do not use a "switch" statement with a bad "case" [PB.SBC-3]
22-46.不要使用'=='或'!='比较对象/ Do not use '==' or '!=' to compare objects [PB.UEIC-3]
22-47.确保'Iterator.next()'方法实现抛出'NoSuchElementException'/ Ensure 'Iterator.next()' method implementations throw 'NoSuchElementException' [PB.CTNSE-4]
22-48.确保方法返回值被使用/ Ensure method return values are used [PB.NASSIG-4]
22-49.避免可疑的八进制溢出/ Avoid suspicious octal escapes [PB.OE-5]
22-50.确保类或接口有同名且文件声明为"public"/ Ensure that the class or interface that has the same name as the file is declared "public" [PB.PCSF-5]
 
23. Portability [PORT]
23-1.不要使用'System.getenv ()'/ Do not use 'System.getenv ()' [PORT.ENV-1]
23-2.不要刻板的编写'/n'或'/r'来分隔行/ Do not hard code '/n', or '/r' as a line separator [PORT.LNSP-1]
23-3.不要直接使用"java.awt.peer.*"接口/ Do not use "java.awt.peer.*" interfaces directly [PORT.PEER-1]
23-4.不要使用'Runtime.exec()'/ Do not use 'Runtime.exec()' [PORT.EXEC-3]
23-5.不要使用用户定义"native"方法/ Do not use user-defined "native" methods [PORT.NATV-3]
 
24. Security [SECURITY]
24-1.在'writeObject()'方法中不要让DataOutputStream通过二进制/ Do not pass byte arrays to DataOutputStream in the 'writeObject()' method [SECURITY.CBA-1]
24-2.使所有成员类"private"/ Make all member classes "private" [SECURITY.INNER-1]
24-3.不要对类对象名进行比较/ Do not compare Class objects by name [SECURITY.CMP-2]
24-4.不要使用匿名类/ Do not use inner classes [SECURITY.AUIC-3]
24-5.为了安全使你的'clone ()'方法为"final"/ Make your 'clone ()' method "final" for security [SECURITY.CLONE-3]
24-6.使你的类nondeserializeabl/ Make your classes nondeserializeable [SECURITY.DSER-5]
24-7.使你的类不能克隆/ Make your classes noncloneable [SECURITY.MCNC-5]
24-8.为所有'Serializable'类实现'readObject()'/ Implement 'readObject()' for all 'Serializable' classes [SECURITY.OROM-5]
24-9.不要依赖"package"范围/ Do not depend on "package" scope [SECURITY.PKG-5]
24-10.使你的类不能序列化/ Make your classes nonserializeable [SECURITY.SER-5]
 
25. Serialization [SERIAL]
25-1.避免类实现'Externalizable'但不要定义一个空自变量构造器/ Avoid classes that implement 'Externalizable' but do not define a no-argument constructor [SERIAL.ENNAC-2]
25-2.避免能够序列化的类在零自变量的构造器外继承一个超类/ Avoid serializable classes that extend a superclass without a zero-argument constructor [SERIAL.SNNAC-3]
25-3.对于"synchronized"不要声明'readObject()'方法/ Do not declare the 'readObject()' method as "synchronized" [SERIAL.SROS-3]
25-4.确保能够序列化的类是正确的/ Ensure Serializable classes are correct [SERIAL.NSFSC-4]
 
26. Servlets [SERVLET]
26-1.声明一个"public"构造器获取为空参数/ Declare a "public" constructor that takes no parameters [SERVLET.MDC-1]
26-2.把System.out.println或System.err.println的使用减少的最低/ Minimize use of System.out.println or System.err.println [SERVLET.SOP-2]
26-3.不要在Servlet类中使用'SingleThreadModel'/ Do not use 'SingleThreadModel' in Servlet classes [SERVLET.STM-2]
26-4.在Servlets中尽量减少同步/ Minimize synchronization in Servlets [SERVLET.SYN-2]
26-5.不要在Servlet类中使用JDBC代码/ Do not use JDBC code in Servlet classes [SERVLET.AJDBC-3]
26-6.不要使用'java.beans.Beans.instantiate ()'/ Do not use 'java.beans.Beans.instantiate ()' [SERVLET.BINS-3]
26-7.确保在web.xml file文件中Servlet类有他们自己的引用名Ensure Servlet classes have their own reference names in the web.xml file [SERVLET.SNM-3]
26-8.使用一个背景对象管理HTTP请求参数/ Use a Context Object to manage HTTP request parameters [SERVLET.UCO-4]
 
27. Struts Framework [STRUTS]
27-1.在一个表格bean中每个字段都应该有适当的getter和setter方法/ Each field in a form bean should have an appropriate getter and setter method [STRUTS.FIELDS-3]
27-2.仅仅在表格beans里包含getter和setter方法/ Include only getter and setter methods in form beans [STRUTS.FORM-3]
27-3.不要在Struts Action类中声明实例变量/ Do not declare instance variables in Struts Action classes [STRUTS.INST-3]
27-4.不要在Struts代码中构造任何'getParameter'调用/ Do not make any calls to 'getParameter' in Struts code [STRUTS.PARAM-4]
 
28. Threads & Synchronization [TRS]
28-1.避免调用'Thread.resume()', 'Thread.stop()', 'Thread.suspend()',或'Runtime.runFinalizersonExit()'/ Avoid calling 'Thread.resume()', 'Thread.stop()', 'Thread.suspend()', or 'Runtime.runFinalizersonExit()' [TRS.THRD-1]
28-2.给线程的子集一个'run ()'方法/ Give subclasses of Thread a 'run ()' method [TRS.MRUN-2]
28-3.确保'wait()', 'notify()'和'notifyAll()'被调用于一个对象且在他们的方法范围内明确的被同步/ Ensure 'wait()', 'notify()' and 'notifyAll()' are invoked on an object that is clearly synchronized in its enclosing method scope [TRS.NSYN-2]
28-4.仅仅在一个"while"或"do-while"循环中调用'wait ()'/ Call 'wait ()' only inside a "while" or "do-while" loop [TRS.UWIL-2]
28-5.使用'wait()'和'notifyAll()'代替轮流检测的循环/ Use 'wait()' and 'notifyAll()' instead of polling loops [TRS.UWNA-2]
28-6.不要使用'notify()';使用'notifyAll()'来代替/ Do not use 'notify()'; use 'notifyAll()' instead [TRS.ANF-3]
28-7.不要使用'java.lang.ThreadGroup'类型的变量/ Do not use variables of type 'java.lang.ThreadGroup' [TRS.AUTG-3]
28-8.不要使用'Thread.yield'/ Do not use 'Thread.yield' [TRS.AUTY-3]
28-9.不要从一个"synchronized"方法中调用一个"synchronized"方法引起死锁/ Do not cause deadlocks by calling a "synchronized" method from a "synchronized" method [TRS.CSFS-3]
28-10.不要在一个继承于'Thread'的类的构造器里调用'start()'/ Do not call 'start()' inside the constructors of classes that extend 'Thread' [TRS.CSTART-3]
28-11.不要使用"Double Check Locking Pattern"/ Do not use "Double Check Locking Pattern" [TRS.DCL-3]
28-12.不要捕获'IllegalMonitorStateException'/ Do not catch 'IllegalMonitorStateException' [TRS.IMSE-3]
28-13.类实现'java.lang.Runnable'时不要调用'run()'方法/ Do not call 'run()' methods of classes implementing 'java.lang.Runnable' [TRS.IRUN-3]
28-14.不要同步非"final"字段/ Do not synchronize on non-"final" fields [TRS.SOUF-3]
28-15.避免缓慢初始化,那是不安全的线程/ Avoid lazy initializations that are not thread-safe [TRS.ILI-4]
28-16.不要在方法声明中使用"synchronized" modifier/ Do not use the "synchronized" modifier in the method declaration [TRS.NSM-5]
28-17.在方法中使用"synchronized"要实现'Runnable.run()'/ Use the "synchronized" modifier on methods that implement 'Runnable.run()' [TRS.RUN-5]
 
29.        Unused Code [UC]
29-1.避免无用的局部变量   /Avoid unused local variables [UC.AUV-2]
29-2.避免对从未读取的变量赋值/ Avoid assignments to variables that are never read [UC.AVNR-2]
29-3.避免不使用的"private"字段/ Avoid unused "private" fields [UC.PF-2]
29-4.避免不使用的"private"方法/ Avoid unused "private" methods [UC.PM-2]
29-5.在"catch"块中使用捕获异常/ Use a caught exception in the "catch" block [UC.UCATCH-2]
29-6.避免不使用"import"的语句/ Avoid unused "import" statements [UC.UIMPORT-2]
29-7.避免不使用的参数/ Avoid unused parameters [UC.UP-2]
29-8.避免不使用的"private"类或接口/ Avoid unused "private" classes or interfaces [UC.UPC-2]
29-9.避免空的static初始化/ Avoid empty static initializers [UC.AESTAT-3]
29-10.避免不使用的标签/ Avoid unused labels [UC.AUL-3]
29-11.不要明确的"import"java.lang.*中的"package"/ Do not explicitly "import" the java.lang.* "package" //   [UC.DIL-3]
29-11.避免空的'finalize()'方法 /Avoid empty 'finalize()' methods [UC.EF-3]
29-12.避免空的"synchronized" 语句/ Avoid empty "synchronized" statements [UC.SNE-3]
29-13.避免不必要的if语句/ Avoid unnecessary 'if' statements [UC.UCIF-3]
29-14.避免在"void"方法最后使用不必要的"return"语句/ Avoid unnecessary "return" statement at the end of    "void" methods [UC.VR-3]
29-14.确保使用的类没有明确继承'java.lang.Object'/ Ensure that classes do not explicitly extend 'java.lang.Object' [UC.AEEO-4] /
29-15.避免多余的throw子句/ Avoid redundant throw clauses [UC.ARTD-4]
29-16.避免不必要的"boolean"比较/ Avoid unnecessary "boolean" comparisons [UC.BCMP-4]
29-17.不要从已经包含当前类的包里导入类/ Do not import classes from the package that contains the current class [UC.PIMPORT-4]
29-18.避免方法仅仅调用覆写的实现(超类实现)/ Avoid methods that only call the overridden implementation (superclass implementation) [UC.SO-4]
29-19.避免在一个"interface"中不必要的modifiers / Avoid unnecessary modifiers in an "interface" [UC.AAI-2]
 
30. Security (License Required) [SLR]
30-1.不要在'writeObject()'方法中通过可变的对象去'DataOutputStream'/ Do not pass mutable objects to 'DataOutputStream' in the 'writeObject()' method [SLR.CMO-1]
30-2.不要在'main'方法外部设置自定义的安全管理/ Do not set custom security managers outside of 'main' method [SLR.DSSM-1]
30-3.使用'java.security.SecureRandom'来代替'java.util.Random'或'Math.random()/ Use 'java.security.SecureRandom' instead of 'java.util.Random' or 'Math.random()' [SLR.SRD-1]
30-4.不要访问系统属性/ Do not access system properties [SLR.SYSP-1]
30-5.不要定义自定义的类装载器/ Do not define custom class loaders [SLR.CL-2]
30-6.可能的话使用类的SSL-enabled version/ Use the SSL-enabled version of classes when possible [SLR.USC-2]
30-7.不要使用static集合/ Do not use static Collections [SLR.ASC-3]
30-8.检查实例化的'ClassLoader'对象/ Inspect instantiations of 'ClassLoader' objects [SLR.CLI-3]  
30-9.除了'loadClass()'不要覆写任何'ClassLoader'方法/ Do not override any 'ClassLoader' method except 'loadClass()' [SLR.CLO-3]
30-10.不要定义自定义的'SecurityManager'/ Do not define custom 'SecurityManager' [SLR.DCSM-3]
30-11.确保所有异常被记入标准日志或重新抛出/ Ensure all exceptions are either logged with a standard logger or rethrown [SLR.LGE-3]
30-12.不要声明字段为"public" "static" "final" 的'Collection'或'Map'对象/ Do not declare fields as "public" "static" "final" 'Collection' or 'Map' objects [SLR.PSFC-3]
30-13.避免方法返回值可能会暴露他内部的描述/ Avoid methods that might expose internal representations by returning arrays [SLR.RA-3]
30-14.检查序列化对象的实例字段以确保将不会暴露敏感信息/ Inspect instance fields of serializable object to make sure it would not expose sensitive information [SLR.SIF-3]
30-15.确保具有恰当的安全管理设置 //Ensure that an appropriate security manager is set [SLR.SSM-3]
30-16.检查'Date''Time'对象和'System.currentTimeMillis()'方法调用的使用/ Inspect usage of 'Date', 'Time' objects and 'System.currentTimeMillis()' method invocations [SLR.ADT-5]
30-16.从'java.lang.Class' 对象中检查'getName()'的使用/ Inspect usage of 'getName()' from 'java.lang.Class' object [SLR.AUG-5]
30-17.检查'Random'对象或'Math.random()'方法能够揭示恶意代码所在区域/ Inspect 'Random' objects or 'Math.random()' methods that could indicate areas where malicious code has been placed [SLR.RDM-5]
30-18.避免使用main()方法/ Avoid 'main()' methods [SLR.UMAIN-5]
 
31. Security Policy Rules (License Required) [SPR]
31-1.确保所有敏感的方法调用都被记入日志/ Ensure all sensitive method invocations are logged [SPR.ENFL-2]
31-2.保持所有访问控制方法能集中以加强一致性/ Keep all access control methods centralized to enforce consistency [SPR.CACM-3]
31-3.保持所有鉴定方法能集中以加强一致性/ Keep all authentication methods centralized to enforce consistency [SPR.CAM-3]
31-4.调用鉴定方法来加强一致性/ Call authentication methods to enforce consistency [SPR.PAC-4]
31-5.调用访问控制方法来加强一致性/ Call access control methods to enforce consistency [SPR.PACC-4]
31-6.为了防止应用程序泄露敏感信息,不要允许输出异常信息/ Do not pass exception messages into output in order to prevent the application from leaking sensitive information [SPR.PEO-4]
31-7.用一个变量函数封装所有危险数据的返回方法/ Encapsulate all dangerous data returning methods with a validation function [SPR.VPPD-4]
 
32. Web Security (License Required) [WSLR]
32-1.不要在一个web组件中访问类装载器/ Do not access the class loader in a web component [WSLR.ACL-3]
32-2.不要在web组件中使用AWT类/ Do not use AWT classes in Web components [WSLR.AWT-3]
32-3.不要在一个web组件中停止JVM/ Do not stop the JVM in a web component [WSLR.JVM-3]
32-4.不要在一个web组件中调用'Socket.setSocketImplFactory()'或'URL.setURLStreamHandlerFactory()'/ Do not call 'Socket.setSocketImplFactory()' or 'URL.setURLStreamHandlerFactory()' in a web component [WSLR.NSF-3]
32-5.不要在一个web组件中使用static字段/ Do not use static fields in a web component [WSLR.SF-3]
32-6.不要在一个web组件中改变'java.lang.System'的输入流/ Do not change the input streams of 'java.lang.System' in a web component [WSLR.SIS-3]
32-7.不要在一个web组件中询问或更改按却策略信息/ Do not interrogate or modify security policy information in a web component [WSLR.SPI-3]
32-8.不要在一个web组件中使用服务sockets/ Do not use server sockets in web components [WSLR.SS-3]
32-9.不要在一个web组件中调用'System.setProperty()'/ Do not call 'System.setProperty()' in a web component [WSLR.SSP-3]
32-10.不要在一个web组件中使用线程/ Do not use threads in web components [WSLR.THR-3]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
二、内置与自定义的标准组
 
1. 内置的Jtest配置/Built-in Jtest Configurations
Jtest 包含如下的重新装配(内置) Jtest 配置。
/Jtest includes the following preconfigured (built-in) Jtest Configurations:
编码标准组/Coding Standards group

名称
/Name
范围
/Scope
检测的标准
/Standards Checked
测试用例生成
/Test Case Generation
测试用例执行
/Test Case Execution
SUN
JavaTM 编程语言代码规范》
/Code Conventions for the JavaTM Programming Language by Sun
All selected resources
基于 SUN 微系统公司的代码规范准则
Rules based on Sun Microsystems' Code Conventions for the Java Programming Language (available at http://java.sun.com/docs/codeconv/html/CodeConvTOC.doc.html)
None
None
Alur, Cupr Malks 著《 J2EE 核心模式》
/Core J2EE Patterns by Alur, Cupri and Malks
All selected resources
Rules based on Deepak Alur, John Cupri, and Dan Malks' Core J2EE Patterns:Best Practices and Design Strategies book
None
None
Joshua Bloch著
《高效JAVA》
/Effective Java by Joshua Bloch
All selected resources
Rules based on Joshua Bloch's Effective Java book
None
None
Scott Ambler著
《Java编码规范》
/Elements of Java Style by Scott Ambler
All selected resources
Rules based on Scott Ambler's Elements of Java Style book
None
None
Jtest6.0 版本后新规则
/New Rules Since Jtest 6.0
All selected resources
Rules added since Jtest 6.0
None
None
Parasoft 推荐的规则
/Parasoft's Recommended Rules
All selected resources
The basic set of Jtest coding standards; rules are based on various Java resources
None
None
Security - Priority 1 - Must Have
All selected resources
Rules that identify the most critical security vulnerabilities Requires optional Security Analysis license.
None
None
Security - Priority 2 - Should Have
All selected resources
Security - Priority 1 - Must Have rules, plus additional rules that identify a wider range of security vulnerabilities. Requires optional Security Analysis license.
None
None
Security - Priority 3 - Nice to Have
All selected resources
Security - Priority 2 - Should Have rules, plus additional rules that provide a more comprehensive security assessment. Requires optional Security Analysis license.
None
None
Ambysoft
《编写健壮的 Java 代码》
Writing Robust Java Code by Ambysoft
All selected resources
Rules based on Scott Ambler and Ambysoft's Writing Robust Java Code publication (available athttp://www.ambysoft.com/javaCodingStandards.pdf"> http://www.ambysoft.com/javaCodingStandards.pdf).
None
None
Code Smells (TDD)
All selected resources
Rules based on the Code Smells document (available at http://xp.c2.com/CodeSmell.html ) by Kent Beck and Martin Fowler.
None
None

 
 
 
 
 
2. 测试驱动开发(TDD)/Test Driven Development (TDD)

名称
/Name
范围
/Scope
检测的标准
/Standards Checked
测试用例生成
/Test Case Generation
测试用例执行
/Test Case Execution
测试驱动开发
/TDD
All selected resources
Rules based on the Code Smells document (available at http://xp.c2.com/CodeSmell.html), rules that check whether the JUnit test classes are comprehensive for the tested class, and rules from the Critical Rules (Must Have) Jtest Configuration.
None
With code coverage and Design by Contract checking
Reports an error if coverage is not 90% or higher.
Contract著《测试驱动开发设计》TDD with Design by Contract
All selected resources
All rules from the TDD Jtest Configuration, plus rules that determine if code contains appropriate DbC contracts.
For classes without existing test classes and classes with out-of-date test classes
With code coverage and Design by Contract checking
Reports an error if coverage is not 90% or higher.

 
 
 
 
3. Parasoft的自动错误预防组/Parasoft's AEP group
一般集合/General set

名称
/Name
范围
/Scope
检测的标准
/Standards Checked
测试用例生成
/Test Case Generation
测试用例执行
/Test Case Execution
临界的准则
/Critical Rules (Must Have)
All selected resources
Rules Parasoft recommends for all groups implementing coding standards; these are critical Java development rules proven to make immediate and significant improvement to code reliability, functionality, security, and performance
None
None
推荐的准则
/Recommended Rules (Should Have)
All selected resources
Rules Parasoft recommends for groups who have already implemented the Critical Rules
This set includes Critical Rules (Must Have)
None
None
补充的准则
/Supplemental Rules (Nice to Have)
All selected resources
Rules Parasoft recommends for groups who have already implemented the Critical Rules and Recommended Rules

This set includes Recommended Rules (Should Have)
None
None

阶段 I 规定

名称
/Name
范围
/Scope
检测的标准
/Standards Checked
测试用例生成
/Test Case Generation
测试用例执行
/Test Case Execution
每夜构建
/Build Machine Nightly (standards)
Tests all code modified since the specified cutoff date
Designed for automated nightly testing
Same as Parasoft's Recommended Rules
None
None
开发者
/Developer (standards)
Tests only lines of code last modified by the user since the specified cutoff date

Designed for automated nightly testing
Same as Parasoft's Recommended Rules
None
None

阶段 II 规定

名称
/Name
范围
/Scope
检测的标准
/Standards Checked
测试用例生成
/Test Case Generation
测试用例执行
/Test Case Execution
每夜构建
/Build Machine Nightly (standards + generation + execution)
Tests all code modified since the specified cutoff date.
Designed for automated nightly testing
Same as Parasoft's Recommended Rules
For classes without existing test classes and classes with out-of-date test classes
With code coverage and Design by Contract checking
开发者
/Developer (standards + execution)
Tests only lines of code last modified by the user since the specified cutoff date
Designed for automated nightly testing
Same as Parasoft's Recommended Rules
None
The Build Machine Nightly tests will generate test classes and add them to source control. This configuration will access those generated test classes
With code coverage and Design by Contract checking

 
 
 
 
 
 
4. Scope Examples group

名称
/Name
范围
/Scope
检测的标准
/Standards Checked
测试用例生成
/Test Case Generation
测试用例执行
/Test Case Execution
测试所有文件
/Test All Files
All selected resources
Same as Parasoft's Recommended Rules
For classes without existing test classes and classes with out-of-date test classes
With code coverage and Design by Contract checking
测试局部被更改处
/Test Locally Modified
Tests only files and lines of code added or modified on the local machine
Same as Parasoft's Recommended Rules
For classes without existing test classes and classes with out-of-date test classes
With code coverage and Design by Contract checking
测试安装后的更改
/Test Modified Since Installation
Tests all files and lines of code added or modified since the date Jtest was installed
Same as Parasoft's Recommended Rules
For classes without existing test classes and classes with out-of-date test classes
With code coverage and Design by Contract checking

 
 
 
 
 
 
 
5. 其他配置/Other configurations

名称
/Name
范围
/Scope
检测的标准
/Standards Checked
测试用例生成
/Test Case Generation
测试用例执行
/Test Case Execution
检测编码标准
/Check Coding Standards
All selected resources
Same as Parasoft's Recommended Rules
None
None
检测标准和运行单元测试
/Check Standards and Run Unit Tests
All selected resources
Same as Parasoft's Recommended Rules
None
With code coverage and Design by Contract checking
默认配置
/Default Configuration
All selected resources
Same as Parasoft's Recommended Rules, but does not check rules from the Global Static Analysis category
For classes without existing test classes and classes with out-of-date test classes
With code coverage and Design by Contract checking
强制更新单元测试
/Force Regenerate Unit Tests
All selected resources
None
For classes without existing test classes, classes with out-of-date test classes, and classes with up-to-date test classes
None
生成和运行单元测试
/Generate and Run Unit Tests
All selected resources
None
For classes without existing test classes and classes with out-of-date test classes
With code coverage and Design by Contract checking
生成单元测试
/Generate Unit Tests
All selected resources
None
For classes without existing test classes and classes with out-of-date test classes
None
运行所有测试
/Run All Tests
All selected resources
Yes, same as Parasoft's Recommended Rules
For classes without existing test classes and classes with out-of-date test classes
With code coverage and Design by Contract checking
运行单元测试
/Run Unit Tests
All selected resources
None
None
With code coverage and Design by Contract checking

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6. 自定义编码标准分析:概要 /Customizing coding standard analysis: overview
Jtest提供多种途径,为你独特的需求和偏好制作编码标准分析。
/Jtest provides a variety of ways to tailor coding standard analysis to your unique needs and preferences.
配置编码标准分析设置/Configuring coding standard analysis settings
编码标准分析能通过多种不同途径自定义。使用如下表的介绍,以确定如何达成你想要的自定义效果。
/Coding standard analysis can be customized in a variety of different ways. Use the following table as a reference to determine how to achieve the customization effect you are seeking:

Desired Customization
希望的自定义
Required Action
必要的操作
Reference
介绍
在编码标准分析期间测定正确的被检测规则 /
Determine exactly what rules are checked during coding standard analysis
Change the rules settings in the Coding Standards tab of the Jtest Configuration(s) you want to apply
限定编码标准错误报告的每一个规则数量 /
Limit the number of coding standard errors reported per rule
Change the Limit maximum number of errors reported per rule to setting in the Coding Standards tab of the Jtest Configuration(s) you want to apply
自定义内置规则 /
Customize the built-in rules
Edit rule parameters in the Coding Standards tab of the Test Configurations dialog
更改规则种类 /
Change rule categories
Define the changes with rule mappings
更改规则严格设置 /
Change rule severity settings
Define the changes with rule mappings
更改规则标题 /
Change rule headers
Define the changes with rule mappings
创建新的规则种类 /
Create new rule categories
Define the changes with rule mappings
防止 Jtest 报告附加出现的特殊编码标准错误 /
Prevent Jtest from reporting additional occurrences of a specific coding standard error
Suppress the messages using GUI controls or by adding special suppression comments in your source code

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值