Showing 68 of 68 total issues
Avoid excessively long variable names like nameAndMailToNameAndMailMap Open
Map<Map.Entry<String, String>, Map.Entry<String, String>> nameAndMailToNameAndMailMap;
- Read upRead up
- Exclude checks
LongVariable
Since: PMD 0.3
Priority: Medium
Categories: Style
Remediation Points: 50000
Fields, formal arguments, or local variable names that are too long can make the code difficult to follow.
Example:
public class Something {
int reallyLongIntName = -3; // VIOLATION - Field
public static void main( String argumentsList[] ) { // VIOLATION - Formal
int otherReallyLongName = -5; // VIOLATION - Local
for (int interestingIntIndex = 0; // VIOLATION - For
interestingIntIndex < 10;
interestingIntIndex ++ ) {
}
}
When instantiating a SimpleDateFormat object, specify a Locale Open
SimpleDateFormat baseDateFormat = new SimpleDateFormat(dateFormat);
- Read upRead up
- Exclude checks
SimpleDateFormatNeedsLocale
Since: PMD 2.0
Priority: Medium
Categories: Style
Remediation Points: 50000
Be sure to specify a Locale when creating SimpleDateFormat instances to ensure that locale-appropriate formatting is used.
Example:
public class Foo {
// Should specify Locale.US (or whatever)
private SimpleDateFormat sdf = new SimpleDateFormat('pattern');
}
Switch statements should have a default label Open
switch (type) {
case UNCLEAN:
message = "The worktree is in an unclean state. Please stash " +
"or commit your changes.";
break;
- Read upRead up
- Exclude checks
SwitchStmtsShouldHaveDefault
Since: PMD 1.0
Priority: Medium
Categories: Style
Remediation Points: 50000
All switch statements should include a default option to catch any unspecified values.
Example:
public void bar() {
int x = 2;
switch (x) {
case 1: int j = 6;
case 2: int j = 8;
// missing default: here
}
}
Avoid excessively long variable names like BUILTIN_TEMPLATE_PATH Open
private static final String BUILTIN_TEMPLATE_PATH = "TemplateGitInfoClass.java";
- Read upRead up
- Exclude checks
LongVariable
Since: PMD 0.3
Priority: Medium
Categories: Style
Remediation Points: 50000
Fields, formal arguments, or local variable names that are too long can make the code difficult to follow.
Example:
public class Something {
int reallyLongIntName = -3; // VIOLATION - Field
public static void main( String argumentsList[] ) { // VIOLATION - Formal
int otherReallyLongName = -5; // VIOLATION - Local
for (int interestingIntIndex = 0; // VIOLATION - For
interestingIntIndex < 10;
interestingIntIndex ++ ) {
}
}
New exception is thrown in catch block, original stack trace may be lost Open
throw new GitRepositoryException(e.getMessage());
- Read upRead up
- Exclude checks
PreserveStackTrace
Since: PMD 3.7
Priority: Medium
Categories: Style
Remediation Points: 50000
Throwing a new exception from a catch block without passing the original exception into the new exception will cause the original stack trace to be lost making it difficult to debug effectively.
Example:
public class Foo {
void good() {
try{
Integer.parseInt('a');
} catch (Exception e) {
throw new Exception(e); // first possibility to create exception chain
}
try {
Integer.parseInt('a');
} catch (Exception e) {
throw (IllegalStateException)new IllegalStateException().initCause(e); // second possibility to create exception chain.
}
}
void bad() {
try{
Integer.parseInt('a');
} catch (Exception e) {
throw new Exception(e.getMessage());
}
}
}
Private field 'repository' could be made final; it is only initialized in the declaration or constructor. Open
private GitRepository repository;
- Read upRead up
- Exclude checks
ImmutableField
Since: PMD 2.0
Priority: Medium
Categories: Style
Remediation Points: 50000
Identifies private fields whose values never change once they are initialized either in the declaration of the field or by a constructor. This helps in converting existing classes to becoming immutable ones.
Example:
public class Foo {
private int x; // could be final
public Foo() {
x = 7;
}
public void foo() {
int a = x + 2;
}
}
Avoid excessively long variable names like MARKDOWN_TRANSLATION_MAP Open
private static final Map<CharSequence, CharSequence> MARKDOWN_TRANSLATION_MAP = new HashMap<>();
- Read upRead up
- Exclude checks
LongVariable
Since: PMD 0.3
Priority: Medium
Categories: Style
Remediation Points: 50000
Fields, formal arguments, or local variable names that are too long can make the code difficult to follow.
Example:
public class Something {
int reallyLongIntName = -3; // VIOLATION - Field
public static void main( String argumentsList[] ) { // VIOLATION - Formal
int otherReallyLongName = -5; // VIOLATION - Local
for (int interestingIntIndex = 0; // VIOLATION - For
interestingIntIndex < 10;
interestingIntIndex ++ ) {
}
}
Avoid reassigning parameters such as 'name' Open
private String escapeName(String name) {
- Read upRead up
- Exclude checks
AvoidReassigningParameters
Since: PMD 1.0
Priority: Medium High
Categories: Style
Remediation Points: 50000
Reassigning values to incoming parameters is not recommended. Use temporary local variables instead.
Example:
public class Foo {
private void foo(String bar) {
bar = 'something else';
}
}