Skip to content

Commit

Permalink
Fixing spotbugs findings (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
AldenPratt authored Oct 29, 2023
1 parent c4ce67d commit a9cb349
Show file tree
Hide file tree
Showing 15 changed files with 41 additions and 34 deletions.
2 changes: 2 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
<revision>0.7.25</revision>
<changelist>-SNAPSHOT</changelist>
<jenkins.version>2.361</jenkins.version>
<spotbugs.effort>Max</spotbugs.effort>
<spotbugs.threshold>Low</spotbugs.threshold>
</properties>

<developers>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public Collection<AccurevTransaction> getLogs() {

public java.lang.Object[] toArray() {
if (transactions == null) {
return null;
return new java.lang.Object[0];
}

return transactions.toArray();
Expand Down
33 changes: 11 additions & 22 deletions src/main/java/hudson/plugins/accurev/AccurevLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -343,35 +343,24 @@ public static <TResult, TContext> TResult runCommand( //
directoryToRunCommandFrom,
loggerToLogFailuresTo,
listenerToLogFailuresTo);
try {
final int commandExitCode =
runCommandToCompletion(starter, synchronizationLockObjectOrNull);
final InputStream outputFromCommand = stdout.getInput();
final InputStream errorFromCommand = stderr.getInput();
if (commandExitCode != 0) {
logCommandFailure(
machineReadableCommand,
directoryToRunCommandFrom,
humanReadableCommandName,
commandExitCode,
outputFromCommand,
errorFromCommand,
loggerToLogFailuresTo,
listenerToLogFailuresTo);
return null;
}
return commandOutputParser.parse(outputFromCommand, commandOutputParserContext);
} catch (Exception ex) {
logCommandException(

final int commandExitCode = runCommandToCompletion(starter, synchronizationLockObjectOrNull);
final InputStream outputFromCommand = stdout.getInput();
final InputStream errorFromCommand = stderr.getInput();
if (commandExitCode != 0) {
logCommandFailure(
machineReadableCommand,
directoryToRunCommandFrom,
humanReadableCommandName,
ex,
commandExitCode,
outputFromCommand,
errorFromCommand,
loggerToLogFailuresTo,
listenerToLogFailuresTo);
return null;
}
} catch (InterruptedException | IOException ex) {
return commandOutputParser.parse(outputFromCommand, commandOutputParserContext);
} catch (InterruptedException | IOException | UnhandledAccurevCommandOutput ex) {
logCommandException(
machineReadableCommand,
directoryToRunCommandFrom,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class AccurevReferenceTree implements Serializable {
private final String host;
private final String storage;
private AccurevStream stream = null;
private static final long serialVersionUID = 1L;

public AccurevReferenceTree(
String depot, Long streamNumber, String name, String host, String storage) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/hudson/plugins/accurev/AccurevSCM.java
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ public String getPollingStream(Job<?, ?> project, TaskListener listener)

@Extension
@Symbol("accurev")
public static class AccurevSCMDescriptor extends SCMDescriptor<AccurevSCM>
public static final class AccurevSCMDescriptor extends SCMDescriptor<AccurevSCM>
implements ModelObject {

private static final Logger DESCRIPTORLOGGER =
Expand Down Expand Up @@ -1014,7 +1014,7 @@ public DescriptorImpl getDescriptor() {

@Extension
@Symbol("accurevServer")
public static class DescriptorImpl extends Descriptor<AccurevServer> {
public static final class DescriptorImpl extends Descriptor<AccurevServer> {

public DescriptorImpl() {
load();
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/hudson/plugins/accurev/AccurevTransaction.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package hudson.plugins.accurev;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import hudson.model.User;
import hudson.scm.ChangeLogSet;
import hudson.scm.EditType;
Expand Down Expand Up @@ -92,6 +93,9 @@ public Collection<String> getFileRevisions() {
}

@Exported
@SuppressFBWarnings(
value = "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR",
justification = "We hope that AccurevTransaction.author is not null here... Need to fix.")
public String getUser() { // digester wants read/write property, even though it never reads. Duh.
return author.getDisplayName();
}
Expand All @@ -101,6 +105,9 @@ public void setUser(String author) {
}

@Exported
@SuppressFBWarnings(
value = "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR",
justification = "We hope that AccurevTransaction.date is not null here... Need to fix.")
public Date getDate() {
return (Date) date.clone();
}
Expand All @@ -123,6 +130,9 @@ protected void setParent(ChangeLogSet parent) {
}

@Exported
@SuppressFBWarnings(
value = "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR",
justification = "We hope that AccurevTransaction.action is not null here... Need to fix.")
public EditType getEditType() {
if (action.equals("promote")) {
return EditType.EDIT;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/hudson/plugins/accurev/AccurevWorkspace.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class AccurevWorkspace implements Serializable {
private final String host;
private final String storage;
private AccurevStream stream = null;
private static final long serialVersionUID = 1L;

public AccurevWorkspace(
String depot, Long streamNumber, String name, String host, String storage) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/hudson/plugins/accurev/CheckForChanges.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public static boolean checkStreamForChanges(
stream.getName(),
transactionTypes,
dateRange);
if (null != tempTransaction && !tempTransaction.isEmpty()) {
if (!tempTransaction.isEmpty()) {
for (AccurevTransaction t : tempTransaction) {
if (t.getAffectedPaths().isEmpty()
&& (t.getAction().equals("mkstream")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class DetermineRemoteHostname
implements Callable<RemoteWorkspaceDetails, UnknownHostException> {

private final String path;
private static final long serialVersionUID = 1L;

public DetermineRemoteHostname(String path) {
this.path = path;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/hudson/plugins/accurev/GetConfigWebURL.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
public class GetConfigWebURL implements Serializable {

private final String webURL;
private static final long serialVersionUID = 1L;

public GetConfigWebURL(String webURL) {
this.webURL = webURL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public class RefTreeExternalFile implements Serializable {

private final String location;
private final String status;
private static final long serialVersionUID = 1L;

public RefTreeExternalFile(String location, String status) {
this.location = location;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class RemoteWorkspaceDetails implements Serializable {
private final String hostName;
private final String path;
private final String fileSeparator;
private static final long serialVersionUID = 1L;

public RemoteWorkspaceDetails(String hostName, String path) {
this.hostName = hostName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public ReftreeDelegate(AccurevSCM scm) {
super(scm);
}

public String getRefTree() {
public String getSCMRefTree() {
return scm.getReftree();
}

Expand All @@ -49,7 +49,7 @@ protected PollingResult checkForChanges(Job<?, ?> project)
return PollingResult.BUILD_NOW;
} else {
if (Update.hasChanges(
scm, server, accurevEnv, accurevWorkingSpace, listener, launcher, getRefTree())) {
scm, server, accurevEnv, accurevWorkingSpace, listener, launcher, getSCMRefTree())) {
return PollingResult.BUILD_NOW;
} else {
return PollingResult.NO_CHANGES;
Expand Down Expand Up @@ -164,7 +164,7 @@ private boolean doUpdate(File changeLogFile) throws IOException {
accurevWorkingSpace,
listener,
launcher,
getRefTree(),
getSCMRefTree(),
updateLogFile);
}

Expand Down Expand Up @@ -209,12 +209,12 @@ protected ArgumentListBuilder getRelocateCommand() {
chrefcmd.add("chref");
Command.addServer(chrefcmd, server);
chrefcmd.add("-r");
chrefcmd.add(getRefTree());
chrefcmd.add(getSCMRefTree());
return chrefcmd;
}

protected boolean validateCheckout(Run<?, ?> build) {
String reftree = getRefTree();
String reftree = getSCMRefTree();
if (StringUtils.isEmpty(reftree)) {
listener.fatalError("Must specify a reference tree");
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public WorkspaceDelegate(AccurevSCM scm) {
}

@Override
public String getRefTree() {
public String getSCMRefTree() {
return null;
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/jenkins/plugins/accurev/AccurevTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
public class AccurevTool extends ToolInstallation
implements NodeSpecific<AccurevTool>, EnvironmentSpecific<AccurevTool> {

public static final transient String DEFAULT = "Default";
private static final String DEFAULT = "Default";
private static final long serialVersionUID = 1;
private static final Logger LOGGER = Logger.getLogger(AccurevTool.class.getName());

Expand Down Expand Up @@ -118,7 +118,7 @@ public DescriptorImpl getDescriptor() {

@Extension
@Symbol("accurevTool")
public static class DescriptorImpl extends ToolDescriptor<AccurevTool> {
public static final class DescriptorImpl extends ToolDescriptor<AccurevTool> {

public DescriptorImpl() {
super();
Expand Down

0 comments on commit a9cb349

Please sign in to comment.