Skip to content

Commit

Permalink
Spotbugs fixes and tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
rsandell committed Jun 12, 2021
1 parent 2b55571 commit fb7cc53
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 15 deletions.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
<surefire.rerunFailingTestsCount>3</surefire.rerunFailingTestsCount>
<reuseForks>false</reuseForks>
<forkCount>0.5C</forkCount>
<spotbugs.threshold>High</spotbugs.threshold>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public static final class DescriptorImpl extends Descriptor<GerritManagement> {

@Override
public String getDisplayName() {
return null; // unused
return ""; // unused
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public BuildMemoryReport() {
public int compare(GerritTriggeredEvent a, GerritTriggeredEvent b) {
int to = a.getEventCreatedOn().compareTo(b.getEventCreatedOn()) * -1;
if (to == 0) {
return Integer.valueOf(a.hashCode()).compareTo(b.hashCode()) * -1;
return Integer.compare(a.hashCode(), b.hashCode()) * -1;
}
return to;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,20 @@ protected void printTo(PrintWriter out) throws IOException {
Job job = listener.findJob();
GerritTrigger trigger = listener.getTrigger();
if (job != null) {
out.format(" * __Job: %s _(%s)___\n", job.getFullDisplayName(), listener.getJob());
out.format(" * __Job: %s _(%s)___%n", job.getFullDisplayName(), listener.getJob());
} else {
out.format(" * __Job: _(%s)___\n", listener.getJob());
out.format(" * __Job: _(%s)___%n", listener.getJob());
}
if (trigger != null) {
out.println(" - Trigger on: ");
List<GerritProject> projects = trigger.getGerritProjects();
for (int i = 0; i < Math.min(MAX_PROJECT_BRANCH_LIST_LENGTH, projects.size()); i++) {
GerritProject pr = projects.get(i);
out.format(" * _%s_: %s\n", pr.getCompareType().getDisplayName(), pr.getPattern());
out.format(" * _%s_: %s%n", pr.getCompareType().getDisplayName(), pr.getPattern());
List<Branch> branches = pr.getBranches();
for (int j = 0; j < Math.min(MAX_PROJECT_BRANCH_LIST_LENGTH, branches.size()); j++) {
Branch branch = branches.get(0);
out.format(" - _%s_: %s\n",
out.format(" - _%s_: %s%n",
branch.getCompareType().getDisplayName(), branch.getPattern());
}
if (branches.size() >= MAX_PROJECT_BRANCH_LIST_LENGTH) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public int compare(GerritTriggeredEvent o1, GerritTriggeredEvent o2) {
if (o1 == null && o2 != null) {
return -1;
}
return Integer.valueOf(o1.hashCode()).compareTo(o2.hashCode());
return Integer.compare(o1.hashCode(), o2.hashCode());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ private void addThisTriggerAsListener(Job project) {
* @param project the project
* @return a new listener instance
*/
/*package*/ static EventListener createListener(Job project) {
/*package*/ static EventListener createListener(Job<?, ?> project) {
return new EventListener(project);
}

Expand All @@ -567,6 +567,9 @@ private void addThisTriggerAsListener(Job project) {
* @see #createListener(hudson.model.Job)
*/
/*package*/ EventListener createListener() {
if (job == null) {
throw new IllegalStateException("job is not set");
}
return createListener(job);
}

Expand Down Expand Up @@ -1071,8 +1074,12 @@ public boolean isInteresting(GerritTriggeredEvent event) {
}
}
} catch (PatternSyntaxException pse) {
String name = "null";
if (job != null) {
name = job.getName();
}
logger.error(MessageFormat.format("Exception caught for project {0} and pattern {1}, message: {2}",
new Object[]{job.getName(), p.getPattern(), pse.getMessage()}));
name, p.getPattern(), pse.getMessage()));
}
}
logger.trace("Event is not interesting; event: {}", event);
Expand Down Expand Up @@ -1960,8 +1967,12 @@ public void updateTriggerConfigURL() {
// Now that the dynamic project list has been loaded, we can "count down"
// the latch so that the EventListener thread can begin to process events.
if (projectListIsReady.getCount() > 0) {
logger.debug("Trigger config URL updated: {}; latch is currently {}; decrementing it.", job.getName(),
projectListIsReady.getCount());
String name = "null";
if (job != null) {
name = job.getName();
}
logger.debug("Trigger config URL updated: {}; latch is currently {}; decrementing it.",
name, projectListIsReady.getCount());
}
// Always release all locks otherwise workers will be stuck forever
projectListIsReady.countDown();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public final class GerritTriggerTimer {
/**
* The instance used by the singleton mechanism.
*/
private static GerritTriggerTimer instance = null;
private static volatile GerritTriggerTimer instance = null;

/**
* The timer handler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ public ComboBoxModel doFillPatternItems(@QueryParameter("serverName")
}
@Override
public String getDisplayName() {
return null;
return "";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
package com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data;

import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
import edu.umd.cs.findbugs.annotations.CheckForNull;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.Job;
import hudson.model.Run;
import jenkins.model.Jenkins;

import javax.annotation.Nonnull;

/**
* Wrapper class for smoother serialization of {@link Run } and {@link Job }.
Expand Down Expand Up @@ -223,7 +223,10 @@ public boolean isSameBuild(int otherBuildNumber, String otherParentName) {
* @return true if it is so.
*/
@Deprecated
public boolean equals(@Nonnull Run aBuild) {
public boolean equals(@CheckForNull Run<?, ?> aBuild) {
if (aBuild == null) {
return false;
}
return isSameBuild(aBuild.getNumber(), aBuild.getParent().getFullName());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ public static GerritVersionNumber getGerritVersionNumber(String num) {
return versionNumber;
}

@Override
public boolean equals(final Object o) {
return super.equals(o);
}

@Override
public int hashCode() {
return super.hashCode();
}

/**
* Getter for if the version number is a snapshot.
* @return if it is a snapshot.
Expand Down
11 changes: 11 additions & 0 deletions src/spotbugs/excludesFilter.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<FindBugsFilter>
<Match>
<Class name="~.+\.Messages" />
</Match>
<Match>
<!-- Somehow it seems confused. The RND object is reused at many places -->
<Class name="com.sonyericsson.hudson.plugins.gerrit.trigger.diagnostics.Diagnostics"/>
<Method name="doTriggerDebugEvent" />
<Bug pattern="DMI_RANDOM_USED_ONLY_ONCE" />
</Match>
</FindBugsFilter>

0 comments on commit fb7cc53

Please sign in to comment.