Skip to content

Commit

Permalink
[JENKINS-22160] Fix findings from FindBugs static analysis
Browse files Browse the repository at this point in the history
- SloccountParser: Possible null pointer dereference.
- SloccountDiff: Class defines compareTo(SloccountDiff) and uses Object.equals().
- SloccountPublisher: Format string should use %n rather than \n.
- BreadCrumbResult: Implements same interface as superclass.
  • Loading branch information
mixalturek committed Mar 12, 2014
1 parent fb3dad3 commit f336a18
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
27 changes: 26 additions & 1 deletion src/main/java/hudson/plugins/sloccount/SloccountDiff.java
Expand Up @@ -41,7 +41,6 @@ public SloccountDiff(int lineCount,
this.fileCount = fileCount;
this.fileCountDelta = fileCountDelta;
}


/**
* Compare two instances using lines count, descendant.
Expand All @@ -52,6 +51,32 @@ public int compareTo(SloccountDiff o) {
return o.lineCount - lineCount;
}

// Solve FindBugs warning "SloccountDiff defines compareTo(SloccountDiff)
// and uses Object.equals()"
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + lineCount;
return result;
}

// Solve FindBugs warning "SloccountDiff defines compareTo(SloccountDiff)
// and uses Object.equals()"
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
SloccountDiff other = (SloccountDiff) obj;
if (lineCount != other.lineCount)
return false;
return true;
}

public int getLineCount() {
return lineCount;
}
Expand Down
Expand Up @@ -87,7 +87,7 @@ public boolean perform(AbstractBuild<?,?> build, Launcher launcher, BuildListene
}

if (report.getSourceFiles().size() == 0) {
logger.format("[SLOCCount] No file is matching the input pattern: %s\n",
logger.format("[SLOCCount] No file is matching the input pattern: %s%n",
getRealPattern());
}

Expand Down
Expand Up @@ -205,7 +205,7 @@ public boolean include(File file) {
}
}

private static class BreadCrumbResult extends SloccountResult implements ModelObject, Serializable {
private static class BreadCrumbResult extends SloccountResult implements ModelObject {
/** Serial version UID. */
private static final long serialVersionUID = 0L;

Expand Down
Expand Up @@ -77,7 +77,9 @@ private void parse(java.io.File file, SloccountReportInterface report) throws IO
in = new InputStreamReader(new FileInputStream(file), encoding);
this.parse(in, report);
} finally {
in.close();
if(in != null) {
in.close();
}
}
}

Expand Down

0 comments on commit f336a18

Please sign in to comment.