Skip to content

Commit

Permalink
Fix SpotBugs warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
nikita-tkachenko-datadog committed Jan 30, 2024
1 parent 88b5e10 commit d511656
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ of this software and associated documentation files (the "Software"), to deal
import org.datadog.jenkins.plugins.datadog.model.node.StatusAction;
import org.datadog.jenkins.plugins.datadog.traces.write.TraceWriter;
import org.datadog.jenkins.plugins.datadog.traces.write.TraceWriterFactory;
import org.datadog.jenkins.plugins.datadog.util.SuppressFBWarnings;
import org.datadog.jenkins.plugins.datadog.util.TagsUtil;
import org.jenkinsci.plugins.workflow.actions.ThreadNameAction;
import org.jenkinsci.plugins.workflow.actions.TimingAction;
Expand All @@ -73,6 +74,7 @@ public class DatadogGraphListener implements GraphListener {

private static final Logger logger = Logger.getLogger(DatadogGraphListener.class.getName());

@SuppressFBWarnings("REC_CATCH_EXCEPTION")
@Override
public void onNewHead(FlowNode flowNode) {
WorkflowRun run = getRun(flowNode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.datadog.jenkins.plugins.datadog.model.node.NodeInfoAction;
import org.datadog.jenkins.plugins.datadog.traces.BuildSpanAction;
import org.datadog.jenkins.plugins.datadog.traces.GitInfoUtils;
import org.datadog.jenkins.plugins.datadog.util.SuppressFBWarnings;
import org.datadog.jenkins.plugins.datadog.util.git.GitUtils;
import org.jenkinsci.plugins.workflow.cps.nodes.StepAtomNode;
import org.jenkinsci.plugins.workflow.flow.StepListener;
Expand Down Expand Up @@ -133,6 +134,7 @@ private static String getNodeName(StepContext stepContext) {
* @param stepContext
* @return hostname of the remote node.
*/
@SuppressFBWarnings("REC_CATCH_EXCEPTION")
private static String getNodeHostname(final StepContext stepContext) {
try {
EnvVars envVars = stepContext.get(EnvVars.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ of this software and associated documentation files (the "Software"), to deal
import hudson.model.Job;
import hudson.model.ParameterValue;
import hudson.model.ParametersAction;
import hudson.model.Result;
import hudson.model.Run;
import hudson.model.StringParameterValue;
import hudson.model.TaskListener;
Expand Down Expand Up @@ -135,7 +136,7 @@ public class BuildData implements Serializable {
private String traceId;
private String spanId;

public BuildData(Run run, @Nullable TaskListener listener) throws IOException, InterruptedException {
public BuildData(Run<?, ?> run, @Nullable TaskListener listener) throws IOException, InterruptedException {
if (run == null) {
return;
}
Expand Down Expand Up @@ -180,8 +181,14 @@ public BuildData(Run run, @Nullable TaskListener listener) throws IOException, I
}

// Set Result and completed status
this.result = run.getResult() == null ? null : run.getResult().toString();
this.isCompleted = run.getResult() != null && run.getResult().completeBuild;
Result runResult = run.getResult();
if (runResult != null) {
this.result = runResult.toString();
this.isCompleted = runResult.completeBuild;
} else {
this.result = null;
this.isCompleted = false;
}

// Set Build Number
this.buildNumber = String.valueOf(run.getNumber());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext co
case "committerDate":
committerDate = (String) context.convertAnother(null, String.class);
break;
default:
// unknown tag, could be something serialized by a different version of the plugin
break;
}
reader.moveUp();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext co
case "branch":
gitRepositoryAction.setBranch((String) context.convertAnother(null, String.class));
break;
default:
// unknown tag, could be something serialized by a different version of the plugin
break;
}
reader.moveUp();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext co
case "workspace":
workspace = (String) context.convertAnother(null, String.class);
break;
default:
// unknown tag, could be something serialized by a different version of the plugin
break;
}
reader.moveUp();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext co
case "propagatedQueueTimeMillis":
propagatedQueueTimeMillis = (long) context.convertAnother(null, long.class);
break;
default:
// unknown tag, could be something serialized by a different version of the plugin
break;
}
reader.moveUp();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext co
case "nodeWorkspace":
nodeWorkspace = (String) context.convertAnother(null, String.class);
break;
default:
// unknown tag, could be something serialized by a different version of the plugin
break;
}
reader.moveUp();
}
Expand Down

0 comments on commit d511656

Please sign in to comment.