Quality profiles / java / Sonar way
120 results
Active/Severity | Name [expand/collapse] | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Here are the main reasons why commented code is a code smell :
squid:CommentedOutCodeLine
|
|||||||||||
When several packages are involved in a cycle (package A > package B > package C > package A where ">" means "depends upon"), that means that those packages are highly coupled and that there is no way to reuse/extract one of those packages without importing all the other packages. Such cycle could quickly increase the effort required to maintain an application and to embrace business change. Sonar not only detect cycles between packages but also determines what is the minimum effort to break those cycles. This rule log a violation on each source file having an outgoing dependency to be but in order to break a cycle.
squid:CycleBetweenPackages
|
|||||||||||
One might assume that new BigDecimal(.1) is exactly equal to .1, but it is actually equal to .1000000000000000055511151231257827021181583404541015625. This is so because .1 cannot be represented exactly as a double (or, for that matter, 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 .1, appearances notwithstanding. The (String) constructor, on the other hand, is perfectly predictable: 'new BigDecimal(.1)' is exactly equal to .1, as one would expect. Therefore, it is generally recommended that the (String) constructor be used in preference to this one.
pmd:AvoidDecimalLiteralsInBigDecimalConstructor
|
|||||||||||
Code containing duplicate String literals can usually be improved by declaring the String as a constant field. Example : public class Foo { private void bar() { buz("Howdy"); buz("Howdy"); buz("Howdy"); buz("Howdy"); } private void buz(String x) {} }
pmd:AvoidDuplicateLiterals
|
|||||||||||
Checks that class parameter names conform to the specified format The following code snippet illustrates this rule for format "^[A-Z]$": class Something<type> { // Non-compliant } class Something<T> { // Compliant }
checkstyle:com.puppycrawl.tools.checkstyle.checks.naming.ClassTypeParameterNameCheck
|
|||||||||||
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. This version uses PMD's type resolution facilities, and can detect if the class implements or extends a Cloneable class
pmd:CloneMethodMustImplementCloneable
|
|||||||||||
Calling overridable methods during construction poses a risk of invoking methods on an incompletely constructed object
and can be difficult to discern. It may leave the sub-class unable to construct its superclass or forced to replicate
the construction process completely within itself, losing the ability to call super().
If the default constructor contains a call to an overridable method, the subclass may be completely uninstantiable.
Note that this includes method calls throughout the control flow graph - i.e., if a constructor Foo() calls
a private method bar() that calls a public method buz(), this denotes a problem.
public class SeniorClass { public SeniorClass(){ toString(); //may throw NullPointerException if overridden } public String toString(){ return "IAmSeniorClass"; } } public class JuniorClass extends SeniorClass { private String name; public JuniorClass(){ super(); //Automatic call leads to NullPointerException name = "JuniorClass"; } public String toString(){ return name.toUpperCase(); } }
pmd:ConstructorCallsOverridableMethod
|
|||||||||||
Checks cyclomatic complexity of methods against a specified limit. The complexity is measured by the number of if, while, do, for, ?:, catch, switch, case statements, and operators && and || (plus one) in the body of a constructor, method, static initializer, or instance initializer. It is a measure of the minimum number of possible paths through the source and therefore the number of required tests. Generally 1-4 is considered good, 5-7 ok, 8-10 consider re-factoring, and 11+ re-factor now !
checkstyle:com.puppycrawl.tools.checkstyle.checks.metrics.CyclomaticComplexityCheck
|
|||||||||||
Checks that method type parameter names conform to the specified format The following code snippet illustrates this rule for format "^[A-Z]$": public <type> boolean containsAll(Collection<type> c) { // Non-compliant return null; } public <T> boolean containsAll(Collection<T> c) { // Compliant }
checkstyle:com.puppycrawl.tools.checkstyle.checks.naming.MethodTypeParameterNameCheck
|
|||||||||||
Checks that the order of modifiers conforms to the suggestions in the Java Language specification, sections 8.1.1, 8.3.1 and 8.4.3. The correct order is : public, protected, private, abstract, static, final, transient, volatile, synchronized, native, strictfp.
checkstyle:com.puppycrawl.tools.checkstyle.checks.modifier.ModifierOrderCheck
|
|||||||||||
A field name is all in uppercase characters, which in Sun's Java naming conventions indicate a constant. However, the field is not final. Example : public class Foo { // this is bad, since someone could accidentally // do PI = 2.71828; which is actualy e // final double PI = 3.16; is ok double PI = 3.16; }
pmd:SuspiciousConstantFieldName
|
|||||||||||
The method name and parameter number are suspiciously close to equals(Object), which may mean you are intending to override the equals(Object) method. Example : public class Foo { public int equals(Object o) { // oops, this probably was supposed to be boolean equals } public boolean equals(String s) { // oops, this probably was supposed to be equals(Object) } }
pmd:SuspiciousEqualsMethodName
|
|||||||||||
Checks that package names conform to the specified format. The default value of format has been chosen to match the requirements in the Java Language specification and the Sun coding conventions. However both underscores and uppercase letters are rather uncommon, so most configurations should probably assign value ^[a-z]+(\.[a-z][a-z0-9]*)*$ to format
checkstyle:com.puppycrawl.tools.checkstyle.checks.naming.PackageNameCheck
|
|||||||||||
The check to ensure that requires that comments be the only thing on a line. For the case of // comments that means that the only thing that should precede it is whitespace. It doesn't check comments if they do not end line, i.e. it accept the following: Thread.sleep( 10 <some comment here> ); Format property is intended to deal with the "} // while" example. Rationale: Steve McConnel in "Code Complete" suggests that endline comments are a bad practice. An end line comment would be one that is on the same line as actual code. For example:
Quoting "Code Complete" for the justfication:
His comments on being hard to maintain when the size of the line changes are even more important in the age of automated refactorings.
checkstyle:com.puppycrawl.tools.checkstyle.checks.TrailingCommentCheck
|
|||||||||||
Fields in interfaces are automatically public static final, and methods are public abstract. Classes or interfaces nested in an interface are automatically public and static (all nested interfaces are automatically static). For historical reasons, modifiers which are implied by the context are accepted by the compiler, but are superfluous.
pmd:UnusedModifier
|
|||||||||||
Checks visibility of class members. Only static final members may be public; other class members must be private unless property protectedAllowed or packageAllowed is set.
checkstyle:com.puppycrawl.tools.checkstyle.checks.design.VisibilityModifierCheck
|
|||||||||||