PMD 5.0.4规则整理


# file key age desc
1 \java\android.html CallSuperFirst PMD 4.2.5 Super should be called at the start of the method
2 \java\android.html CallSuperLast PMD 4.2.5 Super should be called at the end of the method
3 \java\android.html DoNotHardCodeSDCard PMD 4.2.6 Use Environment.getExternalStorageDirectory() instead of "/sdcard"
4 \java\basic.html JumbledIncrementer PMD 1.0 Avoid jumbled loop incrementers - its usually a mistake, and is confusing even if intentional.
5 \java\basic.html ForLoopShouldBeWhileLoop PMD 1.02 Some for loops can be simplified to while loops, this makes them more concise.
6 \java\basic.html OverrideBothEqualsAndHashcode PMD 0.4 Override both public boolean Object.equals(Object other), and public int Object.hashCode(), or override neither. Even if you are inheriting a hashCode() from a parent class, consider implementing hashCode and explicitly delegating to your superclass.
7 \java\basic.html DoubleCheckedLocking PMD 1.04 Partially created objects can be returned by the Double Checked Locking pattern when used in Java. An optimizing JRE may assign a reference to the baz variable before it creates the object the reference is intended to point to. For more details refer to: http://www.javaworld.com/javaworld/jw-02-2001/jw-0209-double.html
8 \java\basic.html ReturnFromFinallyBlock PMD 1.05 Avoid returning from a finally block, this can discard exceptions.
9 \java\basic.html UnconditionalIfStatement PMD 1.5 Do not use "if" statements whose conditionals are always true or always false.
10 \java\basic.html BooleanInstantiation PMD 1.2 Avoid instantiating Boolean objects; you can reference Boolean.TRUE, Boolean.FALSE, or call Boolean.valueOf() instead.
11 \java\basic.html CollapsibleIfStatements PMD 3.1 Sometimes two consecutive 'if' statements can be consolidated by separating their conditions with a boolean short-circuit operator.
12 \java\basic.html ClassCastExceptionWithToArray PMD 3.4 When deriving an array of a specific class from your Collection, one should provide an array of the same class as the parameter of the toArray() method. Doing otherwise you will will result in a ClassCastException.
13 \java\basic.html AvoidDecimalLiteralsInBigDecimalConstructor PMD 3.4 One might assume that the result of "new BigDecimal(0.1)" is exactly equal to 0.1, but it is actually equal to .1000000000000000055511151231257827021181583404541015625. This is because 0.1 cannot be represented exactly as a double (or as a binary fraction of any finite length). Thus, the long value that is being passed in to the constructor is not exactly equal to 0.1, appearances notwithstanding. The (String) constructor, on the other hand, is perfectly predictable: 'new BigDecimal("0.1")' is exactly equal to 0.1, as one would expect. Therefore, it is generally recommended that the (String) constructor be used in preference to this one.
14 \java\basic.html MisplacedNullCheck PMD 3.5 The null check here is misplaced. If the variable is null a NullPointerException will be thrown. Either the check is useless (the variable will never be "null") or it is incorrect.
15 \java\basic.html AvoidThreadGroup PMD 3.6 Avoid using java.lang.ThreadGroup; although it is intended to be used in a threaded environment it contains methods that are not thread-safe.
16 \java\basic.html BrokenNullCheck PMD 3.8 The null check is broken since it will throw a NullPointerException itself. It is likely that you used || instead of && or vice versa.
17 \java\basic.html BigIntegerInstantiation PMD 3.9 Don't create instances of already existing BigInteger (BigInteger.ZERO, BigInteger.ONE) and for Java 1.5 onwards, BigInteger.TEN and BigDecimal (BigDecimal.ZERO, BigDecimal.ONE, BigDecimal.TEN)
18 \java\basic.html AvoidUsingOctalValues PMD 3.9 Integer literals should not start with zero since this denotes that the rest of literal will be interpreted as an octal value.
19 \java\basic.html AvoidUsingHardCodedIP PMD 4.1 Application with hard-coded IP addresses can become impossible to deploy in some cases. Externalizing IP adresses is preferable.
20 \java\basic.html CheckResultSet PMD 4.1 Always check the return values of navigation methods (next, previous, first, last) of a ResultSet. If the value return is 'false', it should be handled properly.
21 \java\basic.html AvoidMultipleUnaryOperators PMD 4.2 The use of multiple unary operators may be problematic, and/or confusing. Ensure that the intended usage is not a bug, or consider simplifying the expression.
22 \java\basic.html ExtendsObject PMD 5.0 No need to explicitly extend Object.
23 \java\basic.html CheckSkipResult PMD 5.0 The skip() method may skip a smaller number of bytes than requested. Check the returned value to find out if it was the case or not.
24 \java\basic.html AvoidBranchingStatementAsLastInLoop PMD 5.0 Using a branching statement as the last part of a loop may be a bug, and/or is confusing. Ensure that the usage is not a bug, or consider using another approach.
25 \java\basic.html DontCallThreadRun PMD 4.3 Explicitly calling Thread.run() method will execute in the caller's thread of control. Instead, call Thread.start() for the intended behavior.
26 \java\basic.html DontUseFloatTypeForLoopIndices PMD 4.3 Don't use floating point for loop indices. If you must use floating point, use double unless you're certain that float provides enough precision and you have a compelling performance need (space or time).
27 \java\braces.html IfStmtsMustUseBraces PMD 1.0 Avoid using if statements without using braces to surround the code block. If the code formatting or indentation is lost then it becomes difficult to separate the code being controlled from the rest.
28 \java\braces.html WhileLoopsMustUseBraces PMD 0.7 Avoid using 'while' statements without using braces to surround the code block. If the code formatting or indentation is lost then it becomes difficult to separate the code being controlled from the rest.
29 \java\braces.html IfElseStmtsMustUseBraces PMD 0.2 Avoid using if..else statements without using surrounding braces. If the code formatting or indentation is lost then it becomes difficult to separate the code being controlled from the rest.
30 \java\braces.html ForLoopsMustUseBraces PMD 0.7 Avoid using 'for' statements without using curly braces. If the code formatting or indentation is lost then it becomes difficult to separate the code being controlled from the rest.
31 \java\clone.html ProperCloneImplementation PMD 1.4 Object clone() should be implemented with super.clone().
32 \java\clone.html CloneThrowsCloneNotSupportedException PMD 1.9 The method clone() should throw a CloneNotSupportedException.
33 \java\clone.html CloneMethodMustImplementCloneable PMD 1.9 The method clone() should only be implemented if the class implements the Cloneable interface with the exception of a final method that only throws CloneNotSupportedException.
34 \java\codesize.html NPathComplexity PMD 3.9 The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity and increase readability.
35 \java\codesize.html ExcessiveMethodLength PMD 0.6 When methods are excessively long this usually indicates that the method is doing more than its name/signature might suggest. They also become challenging for others to digest since excessive scrolling causes readers to lose focus. Try to reduce the method length by creating helper methods and removing any copy/pasted code.
36 \java\codesize.html ExcessiveParameterList PMD 0.9 Methods with numerous parameters are a challenge to maintain, especially if most of them share the same datatype. These situations usually denote the need for new objects to wrap the numerous parameters.
37 \java\codesize.html ExcessiveClassLength PMD 0.6 Excessive class file lengths are usually indications that the class may be burdened with excessive responsibilities that could be provided by external classes or functions. In breaking these methods apart the code becomes more managable and ripe for reuse.
38 \java\codesize.html CyclomaticComplexity PMD 1.03 Complexity directly affects maintenance costs is determined by the number of decision points in a method plus one for the method entry. The decision points include 'if', 'while', 'for', and 'case labels' calls. Generally, numbers ranging from 1-4 denote low complexity, 5-7 denote moderate complexity, 8-10 denote high complexity, and 11+ is very high complexity.
39 \java\codesize.html ExcessivePublicCount PMD 1.04 Classes with large numbers of public methods and attributes require disproportionate testing efforts since combinational side effects grow rapidly and increase risk. Refactoring these classes into smaller ones not only increases testability and reliability but also allows new variations to be developed easily.
40 \java\codesize.html TooManyFields PMD 3.0 Classes that have too many fields can become unwieldy and could be redesigned to have fewer fields, possibly through grouping related fields in new objects. For example, a class with individual city/state/zip fields could park them within a single Address field.
41 \java\codesize.html NcssMethodCount PMD 3.9 This rule uses the NCSS (Non-Commenting Source Statements) algorithm to determine the number of lines of code for a given method. NCSS ignores comments, and counts actual statements. Using this algorithm, lines of code that are split are counted as one.
42 \java\codesize.html NcssTypeCount PMD 3.9 This rule uses the NCSS (Non-Commenting Source Statements) algorithm to determine the number of lines of code for a given type. NCSS ignores comments, and counts actual statements. Using this algorithm, lines of code that are split are counted as one.
43 \java\codesize.html NcssConstructorCount PMD 3.9 This rule uses the NCSS (Non-Commenting Source Statements) algorithm to determine the number of lines of code for a given constructor. NCSS ignores comments, and counts actual statements. Using this algorithm, lines of code that are split are counted as one.
44 \java\codesize.html TooManyMethods PMD 4.2 A class with too many methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.
45 \java\comments.html CommentRequired PMD 5.0 Denotes whether comments are required (or unwanted) for specific language elements.
46 \java\comments.html CommentSize PMD 5.0 Determines whether the dimensions of non-header comments found are within the specified limits.
47 \java\comments.html CommentContent PMD 5.0 A rule for the politically correct... we don't want to offend anyone.
48 \java\controversial.html UnnecessaryConstructor PMD 1.0 This rule detects when a constructor is not necessary; i.e., when there is only one constructor, its public, has an empty body, and takes no arguments.
49 \java\controversial.html NullAssignment PMD 1.02 Assigning a "null" to a variable (outside of its declaration) is usually bad form. Sometimes, this type of assignment is an indication that the programmer doesn't completely understand what is going on in the code. NOTE: This sort of assignment may used in some cases to dereference objects and encourage garbage collection.
50 \java\controversial.html OnlyOneReturn PMD 1.0 A method should have only one exit point, and that should be the last statement in the method.
51 \java\controversial.html AssignmentInOperand PMD 1.03 Avoid assignments in operands; this can make code more complicated and harder to read.
52 \java\controversial.html AtLeastOneConstructor PMD 1.04 Each class should declare at least one constructor.
53 \java\controversial.html DontImportSun PMD 1.5 Avoid importing anything from the 'sun.*' packages. These packages are not portable and are likely to change.
54
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值