Skip to content
Permalink
Browse files
[JENKINS-22160] Fix findings from FindBugs static analysis
- 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 f336a1898e7699c22597abcf21861fd915fde943
Showing 4 changed files with 31 additions and 4 deletions.
@@ -41,7 +41,6 @@ public SloccountDiff(int lineCount,
this.fileCount = fileCount;
this.fileCountDelta = fileCountDelta;
}


/**
* Compare two instances using lines count, descendant.
@@ -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;
}
@@ -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());
}

@@ -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;

@@ -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();
}
}
}

0 comments on commit f336a18

Please sign in to comment.