Basic Java practices - provided by PMD
JumbledIncrementer
Avoid jumbled loop incrementers - its usually a mistake, and is confusing even if intentional.
ForLoopShouldBeWhileLoop
Some for loops can be simplified to while loops, this makes them more concise.
OverrideBothEqualsAndHashcode
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.
DoubleCheckedLocking
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.
ReturnFromFinallyBlock
Avoid returning from a finally block, this can discard exceptions.
UnconditionalIfStatement
Do not use "if" statements whose conditionals are always true or always false.
BooleanInstantiation
Avoid instantiating Boolean objects; you can reference Boolean.TRUE, Boolean.FALSE, or call Boolean.valueOf() instead.
CollapsibleIfStatements
Sometimes two consecutive 'if' statements can be consolidated by separating their conditions with a boolean short-circuit operator.
ClassCastExceptionWithToArray
When deriving an array of a specific class from your Collection, one should provide an array ofthe same class as the parameter of the toArray() method. Doing otherwise you will will result in a ClassCastException.
AvoidDecimalLiteralsInBigDecimalConstructor
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 finitelength).
Thus, the long value that is being passed in to the constructor is not exactly equal to 0.1,appearances not with standing.
The (String) constructor, on the other hand, is perfectly predictable: 'new BigDecimal("0.1")' isexactly equal to 0.1, as one would expect. Therefore, it is generally recommended that the(String) constructor be used in preference to this one.
MisplacedNullCheck
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.
AvoidThreadGroup
Avoid using java.lang.ThreadGroup; although it is intended to be used in a threaded environment it contains methods that are not thread-safe.
BrokenNullCheck
The null check is broken since it will throw a NullPointerException itself. It is likely that you used || instead of && or vice versa.
BigIntegerInstantiation
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)
AvoidUsingOctalValues
Integer literals should not start with zero since this denotes that the rest of literal will beinterpreted as an octal value.
AvoidUsingHardCodedIP
Application with hard-coded IP addresses can become impossible to deploy in some cases.Externalizing IP adresses is preferable.
CheckResultSet
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.
AvoidMultipleUnaryOperators
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.
ExtendsObject
No need to explicitly extend Object.
CheckSkipResult
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.
AvoidBranchingStatementAsLastInLoop
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.
DontCallThreadRun
Explicitly calling Thread.run() method will execute in the caller's thread of control. Instead, call Thread.start() for the intended behavior.
DontUseFloatTypeForLoopIndices
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 compellingperformance need (space or time)
Basic Ecmascript (ecmascript)
AssignmentInOperand
Avoid assignments in operands; this can make code more complicated and harder to read.
This is sometime indicative of the bug where the assignment operator '=' was used instead of the equality operator '=='.
UnreachableCode
A 'return', 'break', 'continue', or 'throw' statement should be the last in a block.
Statements after thesewill never execute. This is a bug, or extremely poor style.
InnaccurateNumericLiteral
The numeric literal will have at different value at runtime, which can happen if you provide too muchprecision in a floating point number. This may result in numeric calculations being in error.
ConsistentReturn
ECMAScript does provide for return types on functions, and therefore there is no solid rule as to their usage.
However, when a function does use returns they should all have a value, or all with no value. Mixed return usage is likely a bug, or at best poor style.
ScopeForInVariable
A for-in loop in which the variable name is not explicitly scoped to the enclosing scope with the 'var' keyword canrefer to a variable in an enclosing scope outside the nearest enclosing scope.
This will overwrite theexisting value of the variable in the outer scope when the body of the for-in is evaluated.
When the for-in loophas finished, the variable will contain the last value used in the for-in, and the original value from beforethe for-in loop will be gone.
Since the for-in variable name is most likely intended to be a temporary name, itis better to explicitly scope the variable name to the nearest enclosing scope with 'var'.
EqualComparison
Using == in condition may lead to unexpected results, as the variables are automatically casted to be of the same type. The === operator avoids the casting.
GlobalVariable
This rule helps to avoid using accidently global variables by simply missing the "var" declaration.
Global variables can lead to side-effects that are hard to debug.
AvoidTrailingComma
This rule helps improve code portability due to differences in browser treatment of trailing commas in object or array literals.
No comments:
Post a Comment
Note: only a member of this blog may post a comment.