Skip to content

Commit b8b4f6c

Browse files
authored
Merge pull request #599 from MarkEWaite/fix-or-suppress-spotbugs-warnings
Fix/suppress spotbugs warnings
2 parents 8f927fe + 61b0bc8 commit b8b4f6c

File tree

6 files changed

+73
-13
lines changed

6 files changed

+73
-13
lines changed

pom.xml

-3
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@
5454
<fugue.version>4.7.2</fugue.version>
5555
<!-- jenkins -->
5656
<jenkins.version>2.401.3</jenkins.version>
57-
<!-- security spotbugs -->
58-
<spotbugs.failOnError>false</spotbugs.failOnError>
5957
<spotless.check.skip>false</spotless.check.skip>
6058
</properties>
6159

@@ -389,7 +387,6 @@
389387
<phase>verify</phase>
390388
<configuration>
391389
<failOnError>${spotbugs.failOnError}</failOnError>
392-
<spotbugsXmlOutput>false</spotbugsXmlOutput>
393390
<effort>${spotbugs.effort}</effort>
394391
<threshold>${spotbugs.threshold}</threshold>
395392
<onlyAnalyze>hudson.plugins.jira.*</onlyAnalyze>

src/main/java/hudson/plugins/jira/JiraCreateIssueNotifier.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ private Issue createJiraIssue(AbstractBuild<?, ?> build, String filename) throws
194194
String buildName = getBuildName(vars);
195195
String summary = String.format("Build %s failed", buildName);
196196
String description = String.format(
197-
"%s\n\nThe build %s has failed.\nFirst failed run: %s",
197+
"%s%n%nThe build %s has failed.%nFirst failed run: %s",
198198
(this.testDescription.equals("")) ? "No description is provided" : vars.expand(this.testDescription),
199199
buildName,
200200
getBuildDetailsString(vars));
@@ -345,7 +345,7 @@ private void currentBuildResultFailure(
345345
throws InterruptedException, IOException {
346346

347347
if (previousBuildResult == Result.FAILURE) {
348-
String comment = String.format("Build is still failing.\nFailed run: %s", getBuildDetailsString(vars));
348+
String comment = String.format("Build is still failing.%nFailed run: %s", getBuildDetailsString(vars));
349349

350350
// Get the issue-id which was filed when the previous built failed
351351
String issueId = getIssue(filename);
@@ -406,7 +406,7 @@ private void currentBuildResultSuccess(
406406

407407
if (previousBuildResult == Result.FAILURE || previousBuildResult == Result.SUCCESS) {
408408
String comment =
409-
String.format("Previously failing build now is OK.\n Passed run: %s", getBuildDetailsString(vars));
409+
String.format("Previously failing build now is OK.%n Passed run: %s", getBuildDetailsString(vars));
410410
String issueId = getIssue(filename);
411411

412412
// if issue exists it will check the status and comment or delete the file

src/main/java/hudson/plugins/jira/JiraCreateReleaseNotes.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public void setUp(
135135
if ((realRelease != null) && !realRelease.isEmpty()) {
136136
releaseNotes = site.getReleaseNotesForFixVersion(realProjectKey, realRelease, realFilter);
137137
} else {
138-
listener.getLogger().printf("No release version found, skipping Release Notes generation\n");
138+
listener.getLogger().printf("No release version found, skipping Release Notes generation%n");
139139
}
140140

141141
} catch (Exception e) {

src/main/java/hudson/plugins/jira/JiraSite.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1171,7 +1171,7 @@ public String getReleaseNotesForFixVersion(String projectKey, String versionName
11711171

11721172
StringBuilder sb = new StringBuilder();
11731173
for (Map.Entry<String, Set<String>> entry : releaseNotes.entrySet()) {
1174-
sb.append(String.format("# %s\n", entry.getKey()));
1174+
sb.append(String.format("# %s%n", entry.getKey()));
11751175
for (String issue : entry.getValue()) {
11761176
sb.append(issue);
11771177
sb.append("\n");

src/main/java/hudson/plugins/jira/Updater.java

+3-5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import hudson.scm.SCM;
1818
import java.io.IOException;
1919
import java.io.PrintStream;
20+
import java.lang.reflect.InvocationTargetException;
2021
import java.lang.reflect.Method;
2122
import java.net.URL;
2223
import java.rmi.RemoteException;
@@ -252,7 +253,7 @@ private String createComment(
252253
: "%6$s: Integrated in Jenkins build %2$s (See [%4$s])\n%5$s",
253254
jenkinsRootUrl,
254255
build.getFullDisplayName(),
255-
result != null ? result.color.getImage() : null,
256+
result.color.getImage(),
256257
Util.encode(jenkinsRootUrl + build.getUrl()),
257258
getScmComments(wikiStyle, build, recordScmChanges, jiraIssue),
258259
result.toString());
@@ -404,12 +405,9 @@ private static String getRevision(Entry entry) {
404405
try {
405406
Class<?> clazz = entry.getClass();
406407
Method method = clazz.getMethod("getRevision", (Class[]) null);
407-
if (method == null) {
408-
return null;
409-
}
410408
Object revObj = method.invoke(entry, (Object[]) null);
411409
return (revObj != null) ? revObj.toString() : null;
412-
} catch (Exception e) {
410+
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
413411
return null;
414412
}
415413
}

src/spotbugs/excludesFilter.xml

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<FindBugsFilter>
3+
<!--
4+
Exclusions in this section have been triaged and determined to be
5+
false positives.
6+
-->
7+
<Match>
8+
<!-- Message string names are wrong style for Java but that's how Jenkins does it -->
9+
<Bug pattern="NM_METHOD_NAMING_CONVENTION" />
10+
<Class name="hudson.plugins.jira.Messages" />
11+
<Or>
12+
<Method name="ErrorCommentingIssues" />
13+
<Method name="FailedToConnect" />
14+
<Method name="FailedToUpdateIssue" />
15+
<Method name="FailedToUpdateIssueWithCarryOver" />
16+
<Method name="NoJenkinsUrl" />
17+
<Method name="NoJiraSite" />
18+
<Method name="NoRemoteAccess" />
19+
<Method name="UpdatingIssue" />
20+
</Or>
21+
</Match>
22+
<Match>
23+
<Bug pattern="MS_SHOULD_BE_FINAL" />
24+
<Class name="hudson.plugins.jira.JiraMailAddressResolver" />
25+
<Field name="disabled" />
26+
</Match>
27+
28+
<!--
29+
Here lies technical debt. Exclusions in this section have not yet
30+
been triaged. When working on this section, pick an exclusion to
31+
triage, then:
32+
33+
- Add a @SuppressFBWarnings(value = "[...]", justification = "[...]")
34+
annotation if it is a false positive. Indicate the reason why
35+
it is a false positive, then remove the exclusion from this
36+
section.
37+
38+
- If it is not a false positive, fix the bug, then remove the
39+
exclusion from this section.
40+
-->
41+
<Match>
42+
<Bug pattern="NP_PARAMETER_MUST_BE_NONNULL_BUT_MARKED_AS_NULLABLE" />
43+
<Class name="hudson.plugins.jira.JiraReleaseVersionUpdaterBuilder$DescriptorImpl" />
44+
</Match>
45+
<Match>
46+
<Bug pattern="LI_LAZY_INIT_STATIC" />
47+
<Class name="hudson.plugins.jira.JiraSite" />
48+
<Field name="executorService" />
49+
</Match>
50+
<Match>
51+
<Bug pattern="NP_NONNULL_PARAM_VIOLATION" />
52+
<Class name="hudson.plugins.jira.JiraSession" />
53+
<Method name="createIssue" />
54+
</Match>
55+
<Match>
56+
<Bug pattern="NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE" />
57+
<Class name="hudson.plugins.jira.Updater" />
58+
<Method name="perform" />
59+
</Match>
60+
<Match>
61+
<Bug pattern="NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE" />
62+
<Class name="hudson.plugins.jira.Updater" />
63+
<Method name="perform" />
64+
</Match>
65+
</FindBugsFilter>

0 commit comments

Comments
 (0)