Showing 68 of 68 total issues
Avoid instantiating new objects inside loops Open
tags.put(object.getName(), new JGitTag(revTag));
- Read upRead up
- Exclude checks
AvoidInstantiatingObjectsInLoops
Since: PMD 2.2
Priority: Medium
Categories: Style
Remediation Points: 50000
New objects created within loops should be checked to see if they can created outside them and reused.
Example:
public class Something {
public static void main( String as[] ) {
for (int i = 0; i < 10; i++) {
Foo f = new Foo(); // Avoid this whenever you can it's really expensive
}
}
}
Avoid excessively long variable names like MAIL_TO_NAME_PATTERN Open
private static final Pattern MAIL_TO_NAME_PATTERN;
- 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 excessively long variable names like skipCommitsPattern Open
private Pattern skipCommitsPattern;
- 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 excessively long variable names like originalGitDirFile Open
File originalGitDirFile = new File(foundGitDir, GITDIR_FILE);
- 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 instantiating new objects inside loops Open
Map.Entry<String, String> commitNameAndMail = new AbstractMap.SimpleEntry<>(lineMatcher.group(3), lineMatcher.group(4));
- Read upRead up
- Exclude checks
AvoidInstantiatingObjectsInLoops
Since: PMD 2.2
Priority: Medium
Categories: Style
Remediation Points: 50000
New objects created within loops should be checked to see if they can created outside them and reused.
Example:
public class Something {
public static void main( String as[] ) {
for (int i = 0; i < 10; i++) {
Foo f = new Foo(); // Avoid this whenever you can it's really expensive
}
}
}
Avoid excessively long variable names like commitMessagePattern Open
Pattern commitMessagePattern;
- 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 excessively long variable names like MARKDOWN_TRANSLATOR Open
private static final CharSequenceTranslator MARKDOWN_TRANSLATOR = new LookupTranslator(MARKDOWN_TRANSLATION_MAP);
- 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 instantiating new objects inside loops Open
action.execute(new JGitCommit(commit));
- Read upRead up
- Exclude checks
AvoidInstantiatingObjectsInLoops
Since: PMD 2.2
Priority: Medium
Categories: Style
Remediation Points: 50000
New objects created within loops should be checked to see if they can created outside them and reused.
Example:
public class Something {
public static void main( String as[] ) {
for (int i = 0; i < 10; i++) {
Foo f = new Foo(); // Avoid this whenever you can it's really expensive
}
}
}
Private field 'tags' could be made final; it is only initialized in the declaration or constructor. Open
private Map<String, GitTag> tags;
- 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;
}
}
Prefer StringBuilder (non-synchronized) or StringBuffer (synchronized) over += for concatenating strings Open
shaId += dirtyFlag;
- Read upRead up
- Exclude checks
UseStringBufferForStringAppends
Since: PMD 3.1
Priority: Medium
Categories: Style
Remediation Points: 50000
The use of the '+=' operator for appending strings causes the JVM to create and use an internal StringBuffer. If a non-trivial number of these concatenations are being used then the explicit use of a StringBuilder or threadsafe StringBuffer is recommended to avoid this.
Example:
public class Foo {
void bar() {
String a;
a = 'foo';
a += ' bar';
// better would be:
// StringBuilder a = new StringBuilder('foo');
// a.append(' bar');
}
}
Avoid instantiating new objects inside loops Open
Map.Entry<String, String> properNameAndMail = new AbstractMap.SimpleEntry<>(lineMatcher.group(1), lineMatcher.group(2));
- Read upRead up
- Exclude checks
AvoidInstantiatingObjectsInLoops
Since: PMD 2.2
Priority: Medium
Categories: Style
Remediation Points: 50000
New objects created within loops should be checked to see if they can created outside them and reused.
Example:
public class Something {
public static void main( String as[] ) {
for (int i = 0; i < 10; i++) {
Foo f = new Foo(); // Avoid this whenever you can it's really expensive
}
}
}
Avoid excessively long variable names like originalGitDirPath Open
String originalGitDirPath = readFileToString(originalGitDirFile, UTF_8).trim();
- 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 excessively long variable names like tempSourceFileStream Open
try (FileOutputStream tempSourceFileStream = new FileOutputStream(tempSourceFile)) {
- 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 ++ ) {
}
}
Prefer StringBuilder (non-synchronized) or StringBuffer (synchronized) over += for concatenating strings Open
describe += dirtyFlag;
- Read upRead up
- Exclude checks
UseStringBufferForStringAppends
Since: PMD 3.1
Priority: Medium
Categories: Style
Remediation Points: 50000
The use of the '+=' operator for appending strings causes the JVM to create and use an internal StringBuffer. If a non-trivial number of these concatenations are being used then the explicit use of a StringBuilder or threadsafe StringBuffer is recommended to avoid this.
Example:
public class Foo {
void bar() {
String a;
a = 'foo';
a += ' bar';
// better would be:
// StringBuilder a = new StringBuilder('foo');
// a.append(' bar');
}
}
Avoid excessively long variable names like NAME_AND_MAIL_TO_NAME_AND_MAIL_PATTERN Open
private static final Pattern NAME_AND_MAIL_TO_NAME_AND_MAIL_PATTERN;
- 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 excessively long variable names like checkCommitMessage Open
String checkCommitMessage;
- 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 excessively long variable names like MAIL_TO_MAIL_PATTERN Open
private static final Pattern MAIL_TO_MAIL_PATTERN;
- 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 ++ ) {
}
}
Prefer StringBuilder (non-synchronized) or StringBuffer (synchronized) over += for concatenating strings Open
shaId += dirtyFlag;
- Read upRead up
- Exclude checks
UseStringBufferForStringAppends
Since: PMD 3.1
Priority: Medium
Categories: Style
Remediation Points: 50000
The use of the '+=' operator for appending strings causes the JVM to create and use an internal StringBuffer. If a non-trivial number of these concatenations are being used then the explicit use of a StringBuilder or threadsafe StringBuffer is recommended to avoid this.
Example:
public class Foo {
void bar() {
String a;
a = 'foo';
a += ' bar';
// better would be:
// StringBuilder a = new StringBuilder('foo');
// a.append(' bar');
}
}
Overridable method 'getRepositoryBuilder' called during object construction Open
buildRepository(workTree, gitDir);
- Read upRead up
- Exclude checks
ConstructorCallsOverridableMethod
Since: PMD 1.04
Priority: High
Categories: Style
Remediation Points: 50000
Calling overridable methods during construction poses a risk of invoking methods on an incompletely constructed object and can be difficult to debug. 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.
Example:
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();
}
}
Private field 'distance' could be made final; it is only initialized in the declaration or constructor. Open
private int distance;
- 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;
}
}