diff --git a/src/main/java/org/jenkinsci/plugins/workflow/FilePathUtils.java b/src/main/java/org/jenkinsci/plugins/workflow/FilePathUtils.java index 60586206..a12de116 100644 --- a/src/main/java/org/jenkinsci/plugins/workflow/FilePathUtils.java +++ b/src/main/java/org/jenkinsci/plugins/workflow/FilePathUtils.java @@ -32,7 +32,6 @@ import hudson.remoting.Channel; import hudson.remoting.VirtualChannel; import hudson.slaves.ComputerListener; -import java.io.IOException; import java.util.Collection; import java.util.Collections; import java.util.Map; @@ -143,7 +142,7 @@ static Collection getChannelNames() { addChannel(c.getChannel(), c.getName()); } } - @Override public void preOnline(Computer c, Channel channel, FilePath root, TaskListener listener) throws IOException, InterruptedException { + @Override public void preOnline(Computer c, Channel channel, FilePath root, TaskListener listener) { addChannel(channel, c.getName()); } diff --git a/src/main/java/org/jenkinsci/plugins/workflow/actions/ArgumentsAction.java b/src/main/java/org/jenkinsci/plugins/workflow/actions/ArgumentsAction.java index 5dbc62aa..b926b9dc 100644 --- a/src/main/java/org/jenkinsci/plugins/workflow/actions/ArgumentsAction.java +++ b/src/main/java/org/jenkinsci/plugins/workflow/actions/ArgumentsAction.java @@ -229,13 +229,13 @@ public Object getArgumentValue(@NonNull String argumentName) { public Object getArgumentValueOrReason(@NonNull String argumentName) { Object ob = getArgumentsInternal().get(argumentName); if (ob instanceof Map) { - return Collections.unmodifiableMap((Map)ob); + return Collections.unmodifiableMap((Map)ob); } else if (ob instanceof Set) { - return Collections.unmodifiableSet((Set)ob); + return Collections.unmodifiableSet((Set)ob); } else if (ob instanceof List) { - return Collections.unmodifiableList((List)ob); + return Collections.unmodifiableList((List)ob); } else if (ob instanceof Collection) { - return Collections.unmodifiableCollection((Collection)ob); + return Collections.unmodifiableCollection((Collection)ob); } return ob; } @@ -302,8 +302,8 @@ public boolean isUnmodifiedArguments() { return args; } // helper method to capture generic type - private static UninstantiatedDescribable resolve(DescribableModel model, Map arguments) throws Exception { - return model.uninstantiate2(model.instantiate(arguments)); + private static UninstantiatedDescribable resolve(DescribableModel model, Map arguments) { + return model.uninstantiate2(model.instantiate(arguments, null)); } diff --git a/src/main/java/org/jenkinsci/plugins/workflow/actions/TagsAction.java b/src/main/java/org/jenkinsci/plugins/workflow/actions/TagsAction.java index fd38eba1..b1380e73 100644 --- a/src/main/java/org/jenkinsci/plugins/workflow/actions/TagsAction.java +++ b/src/main/java/org/jenkinsci/plugins/workflow/actions/TagsAction.java @@ -41,7 +41,7 @@ public class TagsAction implements PersistentAction { private static final String displayName = "Tags"; private static final String urlSuffix = "tags"; - private LinkedHashMap tags = new LinkedHashMap<>(); + private final LinkedHashMap tags = new LinkedHashMap<>(); /** * Add a tag key:value pair to this FlowNode, null or empty values are ignored diff --git a/src/main/java/org/jenkinsci/plugins/workflow/flow/FlowCopier.java b/src/main/java/org/jenkinsci/plugins/workflow/flow/FlowCopier.java index 96855988..762ed61c 100644 --- a/src/main/java/org/jenkinsci/plugins/workflow/flow/FlowCopier.java +++ b/src/main/java/org/jenkinsci/plugins/workflow/flow/FlowCopier.java @@ -66,7 +66,7 @@ public static abstract class ByRun extends FlowCopier { Queue.Executable originalExec = original.getExecutable(); Queue.Executable copyExec = copy.getExecutable(); if (originalExec instanceof Run && copyExec instanceof Run) { - copy((Run) originalExec, (Run) copyExec, copy.getListener()); + copy((Run) originalExec, (Run) copyExec, copy.getListener()); } } diff --git a/src/main/java/org/jenkinsci/plugins/workflow/flow/FlowExecution.java b/src/main/java/org/jenkinsci/plugins/workflow/flow/FlowExecution.java index b1fa3af9..ca288540 100644 --- a/src/main/java/org/jenkinsci/plugins/workflow/flow/FlowExecution.java +++ b/src/main/java/org/jenkinsci/plugins/workflow/flow/FlowExecution.java @@ -109,7 +109,7 @@ public FlowDurabilityHint getDurabilityHint() { /** * Should be called by the flow owner after it is deserialized. */ - public /*abstract*/ void onLoad(FlowExecutionOwner owner) throws IOException { + public /*abstract*/ void onLoad(FlowExecutionOwner owner) { if (Util.isOverridden(FlowExecution.class, getClass(), "onLoad")) { onLoad(); } diff --git a/src/main/java/org/jenkinsci/plugins/workflow/flow/FlowExecutionList.java b/src/main/java/org/jenkinsci/plugins/workflow/flow/FlowExecutionList.java index 034f7006..d621d84c 100644 --- a/src/main/java/org/jenkinsci/plugins/workflow/flow/FlowExecutionList.java +++ b/src/main/java/org/jenkinsci/plugins/workflow/flow/FlowExecutionList.java @@ -134,11 +134,7 @@ private synchronized void saveLater() { final List copy = new ArrayList<>(runningTasks.getView()); LOGGER.log(Level.FINE, "scheduling save of {0}", copy); try { - executor.submit(new Runnable() { - @Override public void run() { - save(copy); - } - }); + executor.submit(() -> save(copy)); } catch (RejectedExecutionException x) { LOGGER.log(Level.FINE, "could not schedule save, perhaps because Jenkins is shutting down; saving immediately", x); save(copy); @@ -210,7 +206,7 @@ public ListenableFuture apply(final Function f) { all.add(execs); Futures.addCallback(execs,new FutureCallback>() { @Override - public void onSuccess(List result) { + public void onSuccess(@NonNull List result) { for (StepExecution e : result) { try { f.apply(e); @@ -221,7 +217,7 @@ public void onSuccess(List result) { } @Override - public void onFailure(Throwable t) { + public void onFailure(@NonNull Throwable t) { LOGGER.log(Level.WARNING, null, t); } }, MoreExecutors.directExecutor()); @@ -260,7 +256,7 @@ public static class ResumeStepExecutionListener extends FlowExecutionListener { public void onResumed(@NonNull FlowExecution e) { Futures.addCallback(e.getCurrentExecutions(false), new FutureCallback>() { @Override - public void onSuccess(List result) { + public void onSuccess(@NonNull List result) { if (e.isComplete()) { // WorkflowRun.onLoad will not fire onResumed if the serialized execution was already // complete when loaded, but right now (at least for workflow-cps), the execution resumes @@ -289,7 +285,7 @@ public void onSuccess(List result) { } @Override - public void onFailure(Throwable t) { + public void onFailure(@NonNull Throwable t) { if (t instanceof CancellationException) { LOGGER.log(Level.FINE, "Cancelled load of " + e, t); } else { diff --git a/src/main/java/org/jenkinsci/plugins/workflow/flow/FlowExecutionOwner.java b/src/main/java/org/jenkinsci/plugins/workflow/flow/FlowExecutionOwner.java index af3d8f84..f8a0e322 100644 --- a/src/main/java/org/jenkinsci/plugins/workflow/flow/FlowExecutionOwner.java +++ b/src/main/java/org/jenkinsci/plugins/workflow/flow/FlowExecutionOwner.java @@ -156,6 +156,7 @@ public static FlowExecutionOwner dummyOwner() { private static class DummyOwner extends FlowExecutionOwner { DummyOwner() {} + @NonNull @Override public FlowExecution get() throws IOException { throw new IOException("not implemented"); } @@ -174,7 +175,8 @@ private static class DummyOwner extends FlowExecutionOwner { @Override public int hashCode() { return 0; } - @Override public TaskListener getListener() throws IOException { + @NonNull + @Override public TaskListener getListener() { return TaskListener.NULL; } } diff --git a/src/main/java/org/jenkinsci/plugins/workflow/flow/GlobalDefaultFlowDurabilityLevel.java b/src/main/java/org/jenkinsci/plugins/workflow/flow/GlobalDefaultFlowDurabilityLevel.java index f6ae5838..73ecdeef 100644 --- a/src/main/java/org/jenkinsci/plugins/workflow/flow/GlobalDefaultFlowDurabilityLevel.java +++ b/src/main/java/org/jenkinsci/plugins/workflow/flow/GlobalDefaultFlowDurabilityLevel.java @@ -32,6 +32,7 @@ public DescriptorImpl() { /** Null to use the platform default, which may change over time as enhanced options are available. */ private FlowDurabilityHint durabilityHint = null; + @NonNull @Override public String getDisplayName() { return "Global Default Pipeline Durability Level"; @@ -48,7 +49,7 @@ public void setDurabilityHint(FlowDurabilityHint hint){ } @Override - public boolean configure(StaplerRequest req, JSONObject json) throws FormException { + public boolean configure(StaplerRequest req, JSONObject json) { // TODO verify if this is covered by permissions checks or we need an explicit check here. Object ob = json.opt("durabilityHint"); FlowDurabilityHint hint = null; diff --git a/src/main/java/org/jenkinsci/plugins/workflow/flow/StashManager.java b/src/main/java/org/jenkinsci/plugins/workflow/flow/StashManager.java index 7f90b3b5..cc9e8b34 100644 --- a/src/main/java/org/jenkinsci/plugins/workflow/flow/StashManager.java +++ b/src/main/java/org/jenkinsci/plugins/workflow/flow/StashManager.java @@ -367,11 +367,8 @@ public interface StashAwareArtifactManager /* extends ArtifactManager */ { Map files = new HashMap<>(); for (String path : srcroot.list("**/*", null, false)) { files.put(path, path); - InputStream in = srcroot.child(path).open(); - try { + try(InputStream in = srcroot.child(path).open()) { dstDir.child(path).copyFrom(in); - } finally { - IOUtils.closeQuietly(in); } } if (!files.isEmpty()) { diff --git a/src/main/java/org/jenkinsci/plugins/workflow/graph/FlowNode.java b/src/main/java/org/jenkinsci/plugins/workflow/graph/FlowNode.java index 007ac787..c5655a67 100644 --- a/src/main/java/org/jenkinsci/plugins/workflow/graph/FlowNode.java +++ b/src/main/java/org/jenkinsci/plugins/workflow/graph/FlowNode.java @@ -416,6 +416,7 @@ private synchronized void loadActions() { } @Exported + @NonNull @SuppressWarnings("deprecation") // of override @Override @SuppressFBWarnings(value = "UG_SYNC_SET_UNSYNC_GET", justification = "CopyOnWrite ArrayList, and field load & modification is synchronized") @@ -466,7 +467,7 @@ public int size() { } @Override - public boolean removeAll(Collection c) { + public boolean removeAll(@NonNull Collection c) { boolean changed = actions.removeAll(c); if (changed) { persistSafe(); diff --git a/src/main/java/org/jenkinsci/plugins/workflow/graph/FlowStartNode.java b/src/main/java/org/jenkinsci/plugins/workflow/graph/FlowStartNode.java index 96d3f916..f93c1249 100644 --- a/src/main/java/org/jenkinsci/plugins/workflow/graph/FlowStartNode.java +++ b/src/main/java/org/jenkinsci/plugins/workflow/graph/FlowStartNode.java @@ -24,6 +24,7 @@ package org.jenkinsci.plugins.workflow.graph; +import edu.umd.cs.findbugs.annotations.NonNull; import org.jenkinsci.plugins.workflow.flow.FlowExecution; import java.util.List; @@ -44,6 +45,7 @@ public FlowStartNode(FlowExecution exec, String id) { * @deprecated * Why are you calling a method that always return empty list? */ + @NonNull @Override public List getParents() { return super.getParents(); diff --git a/src/main/java/org/jenkinsci/plugins/workflow/graphanalysis/FilteratorImpl.java b/src/main/java/org/jenkinsci/plugins/workflow/graphanalysis/FilteratorImpl.java index e91228bd..3c263de1 100644 --- a/src/main/java/org/jenkinsci/plugins/workflow/graphanalysis/FilteratorImpl.java +++ b/src/main/java/org/jenkinsci/plugins/workflow/graphanalysis/FilteratorImpl.java @@ -40,8 +40,9 @@ class FilteratorImpl implements Filterator { private Iterator wrapped = null; private Predicate matchCondition = null; + @NonNull @Override - public FilteratorImpl filter(Predicate matchCondition) { + public FilteratorImpl filter(@NonNull Predicate matchCondition) { return new FilteratorImpl<>(this, matchCondition); } diff --git a/src/main/java/org/jenkinsci/plugins/workflow/graphanalysis/FlowScanningUtils.java b/src/main/java/org/jenkinsci/plugins/workflow/graphanalysis/FlowScanningUtils.java index 6b6debf3..b9bc773c 100644 --- a/src/main/java/org/jenkinsci/plugins/workflow/graphanalysis/FlowScanningUtils.java +++ b/src/main/java/org/jenkinsci/plugins/workflow/graphanalysis/FlowScanningUtils.java @@ -52,12 +52,7 @@ private FlowScanningUtils() {} */ @NonNull public static Predicate hasActionPredicate(@NonNull final Class actionClass) { - return new Predicate() { - @Override - public boolean apply(FlowNode input) { - return (input != null && input.getAction(actionClass) != null); - } - }; + return input -> (input != null && input.getAction(actionClass) != null); } // Default predicates, which may be used for common conditions diff --git a/src/main/java/org/jenkinsci/plugins/workflow/graphanalysis/ForkScanner.java b/src/main/java/org/jenkinsci/plugins/workflow/graphanalysis/ForkScanner.java index aca1d3ac..d00c80c0 100644 --- a/src/main/java/org/jenkinsci/plugins/workflow/graphanalysis/ForkScanner.java +++ b/src/main/java/org/jenkinsci/plugins/workflow/graphanalysis/ForkScanner.java @@ -368,7 +368,7 @@ ArrayDeque leastCommonAncestor(@NonNull final Set ArrayDeque parallelForks = new ArrayDeque<>(); // Tracks the discovered forks in order of encounter Predicate notAHead = new Predicate() { // Filter out pre-existing heads - Collection checkHeads = convertToFastCheckable(heads); + final Collection checkHeads = convertToFastCheckable(heads); @Override public boolean apply(FlowNode input) { return !checkHeads.contains(input); } diff --git a/src/main/java/org/jenkinsci/plugins/workflow/graphanalysis/LinearBlockHoppingScanner.java b/src/main/java/org/jenkinsci/plugins/workflow/graphanalysis/LinearBlockHoppingScanner.java index d0dcd16c..4a630d95 100644 --- a/src/main/java/org/jenkinsci/plugins/workflow/graphanalysis/LinearBlockHoppingScanner.java +++ b/src/main/java/org/jenkinsci/plugins/workflow/graphanalysis/LinearBlockHoppingScanner.java @@ -113,7 +113,7 @@ protected FlowNode jumpBlockScan(@CheckForNull FlowNode node, @NonNull Collectio } @Override - protected FlowNode next(@NonNull FlowNode current, @NonNull Collection blackList) { + protected FlowNode next(@CheckForNull FlowNode current, @NonNull Collection blackList) { if (current == null) { return null; } diff --git a/src/main/java/org/jenkinsci/plugins/workflow/graphanalysis/LinearScanner.java b/src/main/java/org/jenkinsci/plugins/workflow/graphanalysis/LinearScanner.java index a20af305..eea4ea8c 100644 --- a/src/main/java/org/jenkinsci/plugins/workflow/graphanalysis/LinearScanner.java +++ b/src/main/java/org/jenkinsci/plugins/workflow/graphanalysis/LinearScanner.java @@ -27,6 +27,7 @@ import com.google.common.base.Predicate; import org.jenkinsci.plugins.workflow.graph.FlowNode; +import edu.umd.cs.findbugs.annotations.CheckForNull; import edu.umd.cs.findbugs.annotations.NonNull; import javax.annotation.concurrent.NotThreadSafe; import java.util.Collection; @@ -78,7 +79,7 @@ protected void setHeads(@NonNull Collection heads) { } @Override - protected FlowNode next(FlowNode current, @NonNull Collection blackList) { + protected FlowNode next(@CheckForNull FlowNode current, @NonNull Collection blackList) { if (current == null) { return null; } @@ -98,8 +99,9 @@ protected FlowNode next(FlowNode current, @NonNull Collection blackLis * @deprecated prefer {@link #filteredNodes(FlowNode, Predicate)} */ @Deprecated + @NonNull @Override - public List filteredNodes(Collection heads, Predicate matchPredicate) { + public List filteredNodes(Collection heads, @NonNull Predicate matchPredicate) { return super.filteredNodes(heads, matchPredicate); } @@ -109,6 +111,7 @@ public List filteredNodes(Collection heads, PredicateDo not pass multiple heads. */ + @NonNull @Override public List filteredNodes(Collection heads, Collection blackList, Predicate matchCondition) { return super.filteredNodes(heads, blackList, matchCondition); @@ -120,7 +123,7 @@ public List filteredNodes(Collection heads, Collection heads, Predicate matchPredicate) { + public FlowNode findFirstMatch(Collection heads, @NonNull Predicate matchPredicate) { return super.findFirstMatch(heads, matchPredicate); } @@ -142,7 +145,7 @@ public FlowNode findFirstMatch(Collection heads, Collection * @param heads Do not pass multiple heads. */ @Override - public void visitAll(Collection heads, FlowNodeVisitor visitor) { + public void visitAll(Collection heads, @NonNull FlowNodeVisitor visitor) { super.visitAll(heads, visitor); } @@ -153,7 +156,7 @@ public void visitAll(Collection heads, FlowNodeVisitor visitor) { * @param heads Nodes to start walking the DAG backwards from. Do not pass multiple heads. */ @Override - public void visitAll(Collection heads, Collection blackList, FlowNodeVisitor visitor) { + public void visitAll(Collection heads, Collection blackList, @NonNull FlowNodeVisitor visitor) { super.visitAll(heads, blackList, visitor); } @@ -163,7 +166,7 @@ public void visitAll(Collection heads, Collection blackList, */ @Deprecated @Override - public FlowNode findFirstMatch(FlowExecution exec, Predicate matchPredicate) { + public FlowNode findFirstMatch(FlowExecution exec, @NonNull Predicate matchPredicate) { return super.findFirstMatch(exec, matchPredicate); } diff --git a/src/main/java/org/jenkinsci/plugins/workflow/graphanalysis/MemoryFlowChunk.java b/src/main/java/org/jenkinsci/plugins/workflow/graphanalysis/MemoryFlowChunk.java index db9e8f20..9f65e888 100644 --- a/src/main/java/org/jenkinsci/plugins/workflow/graphanalysis/MemoryFlowChunk.java +++ b/src/main/java/org/jenkinsci/plugins/workflow/graphanalysis/MemoryFlowChunk.java @@ -52,6 +52,7 @@ public MemoryFlowChunk() { } + @NonNull @Override public FlowNode getFirstNode() { return firstNode; @@ -61,7 +62,7 @@ public void setFirstNode(FlowNode firstNode) { this.firstNode = firstNode; } - + @NonNull @Override public FlowNode getLastNode() { return lastNode; diff --git a/src/main/java/org/jenkinsci/plugins/workflow/graphanalysis/ParallelFlowChunk.java b/src/main/java/org/jenkinsci/plugins/workflow/graphanalysis/ParallelFlowChunk.java index 66b6eb83..7ab75b8e 100644 --- a/src/main/java/org/jenkinsci/plugins/workflow/graphanalysis/ParallelFlowChunk.java +++ b/src/main/java/org/jenkinsci/plugins/workflow/graphanalysis/ParallelFlowChunk.java @@ -12,6 +12,5 @@ public interface ParallelFlowChunk extends FlowChu @NonNull Map getBranches(); - @NonNull void setBranch(@NonNull String branchName, @NonNull ChunkType branchBlock); } diff --git a/src/main/java/org/jenkinsci/plugins/workflow/graphanalysis/ParallelMemoryFlowChunk.java b/src/main/java/org/jenkinsci/plugins/workflow/graphanalysis/ParallelMemoryFlowChunk.java index f8e15c66..9026843f 100644 --- a/src/main/java/org/jenkinsci/plugins/workflow/graphanalysis/ParallelMemoryFlowChunk.java +++ b/src/main/java/org/jenkinsci/plugins/workflow/graphanalysis/ParallelMemoryFlowChunk.java @@ -39,7 +39,7 @@ public class ParallelMemoryFlowChunk extends MemoryFlowChunk implements ParallelFlowChunk { // LinkedHashMap to preserve insert order - private LinkedHashMap branches = new LinkedHashMap<>(); + private final LinkedHashMap branches = new LinkedHashMap<>(); public ParallelMemoryFlowChunk(@NonNull FlowNode firstNode, @NonNull FlowNode lastNode) { super (null,firstNode, lastNode, null); diff --git a/src/main/java/org/jenkinsci/plugins/workflow/log/BrokenLogStorage.java b/src/main/java/org/jenkinsci/plugins/workflow/log/BrokenLogStorage.java index 3b600903..d909dda1 100644 --- a/src/main/java/org/jenkinsci/plugins/workflow/log/BrokenLogStorage.java +++ b/src/main/java/org/jenkinsci/plugins/workflow/log/BrokenLogStorage.java @@ -24,6 +24,7 @@ package org.jenkinsci.plugins.workflow.log; +import edu.umd.cs.findbugs.annotations.NonNull; import hudson.Functions; import hudson.console.AnnotatedLargeText; import hudson.model.BuildListener; @@ -47,20 +48,24 @@ public final class BrokenLogStorage implements LogStorage { public BrokenLogStorage(Throwable x) { this.x = x; } - - @Override public BuildListener overallListener() throws IOException, InterruptedException { + + @NonNull + @Override public BuildListener overallListener() throws IOException { throw new IOException(x); } - - @Override public TaskListener nodeListener(FlowNode node) throws IOException, InterruptedException { + + @NonNull + @Override public TaskListener nodeListener(@NonNull FlowNode node) throws IOException { throw new IOException(x); } - - @Override public AnnotatedLargeText overallLog(FlowExecutionOwner.Executable build, boolean complete) { + + @NonNull + @Override public AnnotatedLargeText overallLog(@NonNull FlowExecutionOwner.Executable build, boolean complete) { return new BrokenAnnotatedLargeText<>(); } - - @Override public AnnotatedLargeText stepLog(FlowNode node, boolean complete) { + + @NonNull + @Override public AnnotatedLargeText stepLog(@NonNull FlowNode node, boolean complete) { return new BrokenAnnotatedLargeText<>(); } diff --git a/src/main/java/org/jenkinsci/plugins/workflow/log/BufferedBuildListener.java b/src/main/java/org/jenkinsci/plugins/workflow/log/BufferedBuildListener.java index 2fc29832..85316ff8 100644 --- a/src/main/java/org/jenkinsci/plugins/workflow/log/BufferedBuildListener.java +++ b/src/main/java/org/jenkinsci/plugins/workflow/log/BufferedBuildListener.java @@ -24,6 +24,7 @@ package org.jenkinsci.plugins.workflow.log; +import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import hudson.CloseProofOutputStream; import hudson.model.BuildListener; @@ -49,7 +50,8 @@ final class BufferedBuildListener implements BuildListener, Closeable, Serializa this.out = out; ps = new PrintStream(out, false, "UTF-8"); } - + + @NonNull @Override public PrintStream getLogger() { return ps; } diff --git a/src/main/java/org/jenkinsci/plugins/workflow/log/ConsoleAnnotators.java b/src/main/java/org/jenkinsci/plugins/workflow/log/ConsoleAnnotators.java index 5d5869c3..f25d09f0 100644 --- a/src/main/java/org/jenkinsci/plugins/workflow/log/ConsoleAnnotators.java +++ b/src/main/java/org/jenkinsci/plugins/workflow/log/ConsoleAnnotators.java @@ -76,7 +76,7 @@ public static ConsoleAnnotator createAnnotator(T context) throws IOExcept ClassFilter.DEFAULT)) { long timestamp = ois.readLong(); if (TimeUnit.HOURS.toMillis(1) > abs(System.currentTimeMillis() - timestamp)) { - @SuppressWarnings("unchecked") ConsoleAnnotator annotator = (ConsoleAnnotator) ois.readObject(); + @SuppressWarnings("unchecked") ConsoleAnnotator annotator = (ConsoleAnnotator) ois.readObject(); return annotator; } } diff --git a/src/main/java/org/jenkinsci/plugins/workflow/log/DelayBufferedOutputStream.java b/src/main/java/org/jenkinsci/plugins/workflow/log/DelayBufferedOutputStream.java index 541e8782..ff366e78 100644 --- a/src/main/java/org/jenkinsci/plugins/workflow/log/DelayBufferedOutputStream.java +++ b/src/main/java/org/jenkinsci/plugins/workflow/log/DelayBufferedOutputStream.java @@ -33,6 +33,8 @@ import java.util.concurrent.TimeUnit; import java.util.logging.Level; import java.util.logging.Logger; + +import edu.umd.cs.findbugs.annotations.NonNull; import jenkins.util.Timer; import org.jenkinsci.remoting.SerializableOnlyOverRemoting; @@ -121,7 +123,7 @@ private static final class FlushControlledOutputStream extends FilterOutputStrea super(out); } - @Override public void write(byte[] b, int off, int len) throws IOException { + @Override public void write(@NonNull byte[] b, int off, int len) throws IOException { out.write(b, off, len); // super method writes one byte at a time! } diff --git a/src/main/java/org/jenkinsci/plugins/workflow/log/FileLogStorage.java b/src/main/java/org/jenkinsci/plugins/workflow/log/FileLogStorage.java index f2789a71..afebd958 100644 --- a/src/main/java/org/jenkinsci/plugins/workflow/log/FileLogStorage.java +++ b/src/main/java/org/jenkinsci/plugins/workflow/log/FileLogStorage.java @@ -24,6 +24,7 @@ package org.jenkinsci.plugins.workflow.log; +import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import hudson.console.AnnotatedLargeText; import hudson.console.ConsoleAnnotationOutputStream; @@ -111,11 +112,13 @@ private synchronized void open() throws IOException { } } - @Override public BuildListener overallListener() throws IOException, InterruptedException { + @NonNull + @Override public BuildListener overallListener() throws IOException { return new BufferedBuildListener(new IndexOutputStream(null)); } - @Override public TaskListener nodeListener(FlowNode node) throws IOException, InterruptedException { + @NonNull + @Override public TaskListener nodeListener(@NonNull FlowNode node) throws IOException { return new BufferedBuildListener(new IndexOutputStream(node.getId())); } @@ -153,14 +156,14 @@ private final class IndexOutputStream extends OutputStream { } } - @Override public void write(byte[] b) throws IOException { + @Override public void write(@NonNull byte[] b) throws IOException { synchronized (FileLogStorage.this) { checkId(id); bos.write(b); } } - @Override public void write(byte[] b, int off, int len) throws IOException { + @Override public void write(@NonNull byte[] b, int off, int len) throws IOException { synchronized (FileLogStorage.this) { checkId(id); bos.write(b, off, len); @@ -194,7 +197,8 @@ private void maybeFlush() { } } - @Override public AnnotatedLargeText overallLog(FlowExecutionOwner.Executable build, boolean complete) { + @NonNull + @Override public AnnotatedLargeText overallLog(@NonNull FlowExecutionOwner.Executable build, boolean complete) { maybeFlush(); return new AnnotatedLargeText(log, StandardCharsets.UTF_8, complete, build) { @Override public long writeHtmlTo(long start, Writer w) throws IOException { @@ -252,7 +256,8 @@ private void maybeFlush() { }; } - @Override public AnnotatedLargeText stepLog(FlowNode node, boolean complete) { + @NonNull + @Override public AnnotatedLargeText stepLog(@NonNull FlowNode node, boolean complete) { maybeFlush(); String id = node.getId(); try (ByteBuffer buf = new ByteBuffer(); @@ -323,7 +328,8 @@ private void maybeFlush() { } @Deprecated - @Override public File getLogFile(FlowExecutionOwner.Executable build, boolean complete) { + @NonNull + @Override public File getLogFile(@NonNull FlowExecutionOwner.Executable build, boolean complete) { return log; } diff --git a/src/main/java/org/jenkinsci/plugins/workflow/log/GCFlushedOutputStream.java b/src/main/java/org/jenkinsci/plugins/workflow/log/GCFlushedOutputStream.java index c794c60b..7e47b7ab 100644 --- a/src/main/java/org/jenkinsci/plugins/workflow/log/GCFlushedOutputStream.java +++ b/src/main/java/org/jenkinsci/plugins/workflow/log/GCFlushedOutputStream.java @@ -33,6 +33,8 @@ import java.util.concurrent.TimeUnit; import java.util.logging.Level; import java.util.logging.Logger; + +import edu.umd.cs.findbugs.annotations.NonNull; import jenkins.util.Timer; /** @@ -48,7 +50,7 @@ final class GCFlushedOutputStream extends FilterOutputStream { FlushRef.register(this, out); } - @Override public void write(byte[] b, int off, int len) throws IOException { + @Override public void write(@NonNull byte[] b, int off, int len) throws IOException { out.write(b, off, len); // super method is surprising } diff --git a/src/main/java/org/jenkinsci/plugins/workflow/log/LogStorage.java b/src/main/java/org/jenkinsci/plugins/workflow/log/LogStorage.java index ffe25c6f..29b7ca07 100644 --- a/src/main/java/org/jenkinsci/plugins/workflow/log/LogStorage.java +++ b/src/main/java/org/jenkinsci/plugins/workflow/log/LogStorage.java @@ -145,7 +145,7 @@ public interface LogStorage { } catch (Exception x) { Logger.getLogger(LogStorage.class.getName()).log(Level.WARNING, null, x); if (build instanceof Run) { - return new File(((Run) build).getRootDir(), "log"); + return new File(((Run) build).getRootDir(), "log"); } else { return new File("broken.log"); // not much we can do } diff --git a/src/main/java/org/jenkinsci/plugins/workflow/log/TaskListenerDecorator.java b/src/main/java/org/jenkinsci/plugins/workflow/log/TaskListenerDecorator.java index d2c220ee..d22033f0 100644 --- a/src/main/java/org/jenkinsci/plugins/workflow/log/TaskListenerDecorator.java +++ b/src/main/java/org/jenkinsci/plugins/workflow/log/TaskListenerDecorator.java @@ -165,12 +165,13 @@ private static class MergedTaskListenerDecorator extends TaskListenerDecorator { private final @NonNull TaskListenerDecorator original; private final @NonNull TaskListenerDecorator subsequent; - MergedTaskListenerDecorator(TaskListenerDecorator original, TaskListenerDecorator subsequent) { + MergedTaskListenerDecorator(@NonNull TaskListenerDecorator original, @NonNull TaskListenerDecorator subsequent) { this.original = original; this.subsequent = subsequent; } - - @Override public OutputStream decorate(OutputStream logger) throws IOException, InterruptedException { + + @NonNull + @Override public OutputStream decorate(@NonNull OutputStream logger) throws IOException, InterruptedException { // TODO BodyInvoker.MergedFilter probably has these backwards return original.decorate(subsequent.decorate(logger)); } @@ -188,14 +189,15 @@ private static class ConsoleLogFilterAdapter extends TaskListenerDecorator { @SuppressFBWarnings(value = "SE_BAD_FIELD", justification = "Explicitly checking for serializability.") private final @NonNull ConsoleLogFilter filter; - ConsoleLogFilterAdapter(ConsoleLogFilter filter) { + ConsoleLogFilterAdapter(@NonNull ConsoleLogFilter filter) { assert filter instanceof Serializable; this.filter = filter; } + @NonNull @SuppressWarnings("deprecation") // the compatibility code in ConsoleLogFilter fails to delegate to the old overload when given a null argument - @Override public OutputStream decorate(OutputStream logger) throws IOException, InterruptedException { - return filter.decorateLogger((AbstractBuild) null, logger); + @Override public OutputStream decorate(@NonNull OutputStream logger) throws IOException, InterruptedException { + return filter.decorateLogger((AbstractBuild) null, logger); } @Override public String toString() { @@ -222,13 +224,14 @@ private static final class DecoratedTaskListener implements BuildListener { private transient PrintStream logger; - DecoratedTaskListener(TaskListener delegate, List decorators) { + DecoratedTaskListener(@NonNull TaskListener delegate, @NonNull List decorators) { this.delegate = delegate; assert !decorators.isEmpty(); assert !decorators.contains(null); this.decorators = decorators; } + @NonNull @Override public PrintStream getLogger() { if (logger == null) { OutputStream base = delegate.getLogger(); @@ -269,12 +272,13 @@ static BuildListener of(BuildListener mainDelegate, TaskListener closeDelegate) private final @NonNull TaskListener mainDelegate; private final @NonNull TaskListener closeDelegate; - private CloseableTaskListener(TaskListener mainDelegate, TaskListener closeDelegate) { + private CloseableTaskListener(@NonNull TaskListener mainDelegate, @NonNull TaskListener closeDelegate) { this.mainDelegate = mainDelegate; this.closeDelegate = closeDelegate; assert closeDelegate instanceof AutoCloseable; } + @NonNull @Override public PrintStream getLogger() { return mainDelegate.getLogger(); } diff --git a/src/test/java/org/jenkinsci/plugins/workflow/ArtifactManagerTest.java b/src/test/java/org/jenkinsci/plugins/workflow/ArtifactManagerTest.java index c371a60b..4ca402f1 100644 --- a/src/test/java/org/jenkinsci/plugins/workflow/ArtifactManagerTest.java +++ b/src/test/java/org/jenkinsci/plugins/workflow/ArtifactManagerTest.java @@ -58,6 +58,8 @@ import java.io.IOException; import java.io.InputStream; import java.net.URL; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.Collections; import java.util.logging.Level; @@ -401,7 +403,7 @@ private void assertFile(VirtualFile f, String contents) throws Exception { assertEquals(contents.length(), f.length()); assertThat(f.lastModified(), not(is(0))); try (InputStream is = f.open()) { - assertEquals(contents, IOUtils.toString(is)); + assertEquals(contents, IOUtils.toString(is, StandardCharsets.UTF_8)); } URL url = f.toExternalURL(); if (url != null) { @@ -416,7 +418,7 @@ private static final class RemoteOpenURL extends MasterToSlaveCallable new NoOpenVF(vf, baseURL)).toArray(VirtualFile[]::new); } - @Override public Collection list(String includes, String excludes, boolean useDefaultExcludes) throws IOException { + @NonNull + @Override public Collection list(@NonNull String includes, String excludes, boolean useDefaultExcludes) throws IOException { return delegate.list(includes, excludes, useDefaultExcludes); } - @Override public VirtualFile child(String string) { + @NonNull + @Override public VirtualFile child(@NonNull String string) { return new NoOpenVF(delegate.child(string), baseURL); } diff --git a/src/test/java/org/jenkinsci/plugins/workflow/flow/DurabilityBasicsTest.java b/src/test/java/org/jenkinsci/plugins/workflow/flow/DurabilityBasicsTest.java index 2d2ddb67..35d487d6 100644 --- a/src/test/java/org/jenkinsci/plugins/workflow/flow/DurabilityBasicsTest.java +++ b/src/test/java/org/jenkinsci/plugins/workflow/flow/DurabilityBasicsTest.java @@ -19,6 +19,9 @@ import java.util.Collection; import java.util.Optional; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.empty; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; /** @@ -84,7 +87,7 @@ public void managePermissionShouldAccessGlobalConfig() throws Throwable { try (ACLContext c = ACL.as(User.getById(USER, true))) { Collection descriptors = Functions.getSortedDescriptorsForGlobalConfigUnclassified(); - assertTrue("Global configuration should not be accessible to READ users", descriptors.size() == 0); + assertThat("Global configuration should not be accessible to READ users", descriptors, empty()); } try (ACLContext c = ACL.as(User.getById(MANAGER, true))) { Collection descriptors = Functions.getSortedDescriptorsForGlobalConfigUnclassified(); diff --git a/src/test/java/org/jenkinsci/plugins/workflow/flow/FlowExecutionListTest.java b/src/test/java/org/jenkinsci/plugins/workflow/flow/FlowExecutionListTest.java index 2ef4533e..8cf59f30 100644 --- a/src/test/java/org/jenkinsci/plugins/workflow/flow/FlowExecutionListTest.java +++ b/src/test/java/org/jenkinsci/plugins/workflow/flow/FlowExecutionListTest.java @@ -165,7 +165,7 @@ public static class NonResumableStep extends Step implements Serializable { @DataBoundConstructor public NonResumableStep() { } @Override - public StepExecution start(StepContext sc) throws Exception { + public StepExecution start(StepContext sc) { return new ExecutionImpl(sc); } diff --git a/src/test/java/org/jenkinsci/plugins/workflow/graph/FlowNodeTest.java b/src/test/java/org/jenkinsci/plugins/workflow/graph/FlowNodeTest.java index 569c1610..f713d901 100644 --- a/src/test/java/org/jenkinsci/plugins/workflow/graph/FlowNodeTest.java +++ b/src/test/java/org/jenkinsci/plugins/workflow/graph/FlowNodeTest.java @@ -593,7 +593,7 @@ public static class DoubleWarningStep extends Step { public DoubleWarningStep() {} @Override - public StepExecution start(StepContext context) throws Exception { + public StepExecution start(StepContext context) { return new StepExecution(context) { @Override public boolean start() throws Exception { diff --git a/src/test/java/org/jenkinsci/plugins/workflow/graphanalysis/FlowScannerTest.java b/src/test/java/org/jenkinsci/plugins/workflow/graphanalysis/FlowScannerTest.java index 6f3e1379..2732725e 100644 --- a/src/test/java/org/jenkinsci/plugins/workflow/graphanalysis/FlowScannerTest.java +++ b/src/test/java/org/jenkinsci/plugins/workflow/graphanalysis/FlowScannerTest.java @@ -87,10 +87,10 @@ public void testAbstractScanner() throws Exception { AbstractFlowScanner linear = new LinearScanner(); // ## Bunch of tests for convertToFastCheckable ## - Assert.assertEquals(Collections.EMPTY_SET, linear.convertToFastCheckable(null)); - Assert.assertEquals(Collections.EMPTY_SET, linear.convertToFastCheckable(new ArrayList<>())); + Assert.assertEquals(Collections.emptySet(), linear.convertToFastCheckable(null)); + Assert.assertEquals(Collections.emptySet(), linear.convertToFastCheckable(new ArrayList<>())); - Collection coll = linear.convertToFastCheckable(Arrays.asList(intermediateNode)); + Collection coll = linear.convertToFastCheckable(Collections.singletonList(intermediateNode)); Assert.assertTrue("Singleton set used for one element", coll instanceof AbstractSet); Assert.assertEquals(1, coll.size()); @@ -125,13 +125,13 @@ public void testAbstractScanner() throws Exception { Collection nullColl = null; Assert.assertTrue(linear.setup(heads, null)); - Assert.assertTrue(linear.setup(heads, Collections.EMPTY_SET)); + Assert.assertTrue(linear.setup(heads, Collections.emptySet())); Assert.assertFalse(linear.setup(nullColl, heads)); Assert.assertFalse(linear.setup(nullColl, null)); Assert.assertFalse(linear.setup(heads, heads)); Assert.assertTrue(linear.setup(heads)); Assert.assertFalse(linear.setup(nullColl)); - Assert.assertFalse(linear.setup(Collections.EMPTY_SET)); + Assert.assertFalse(linear.setup(Collections.emptySet())); Assert.assertTrue(linear.setup(lastNode)); Assert.assertTrue(linear.setup(lastNode, nullColl)); Assert.assertFalse(linear.setup(nullNode)); @@ -145,12 +145,12 @@ public void testAbstractScanner() throws Exception { FlowNode firstEchoNode = exec.getNode("5"); FlowExecution nullExecution = null; - Assert.assertEquals(firstEchoNode, linear.findFirstMatch(heads, Collections.EMPTY_LIST, FlowTestUtils.MATCH_ECHO_STEP)); + Assert.assertEquals(firstEchoNode, linear.findFirstMatch(heads, Collections.emptySet(), FlowTestUtils.MATCH_ECHO_STEP)); Assert.assertEquals(firstEchoNode, linear.findFirstMatch(heads, FlowTestUtils.MATCH_ECHO_STEP)); Assert.assertEquals(firstEchoNode, linear.findFirstMatch(lastNode, FlowTestUtils.MATCH_ECHO_STEP)); Assert.assertEquals(firstEchoNode, linear.findFirstMatch(exec, FlowTestUtils.MATCH_ECHO_STEP)); Assert.assertNull(linear.findFirstMatch(nullColl, FlowTestUtils.MATCH_ECHO_STEP)); - Assert.assertNull(linear.findFirstMatch(Collections.EMPTY_SET, FlowTestUtils.MATCH_ECHO_STEP)); + Assert.assertNull(linear.findFirstMatch(Collections.emptySet(), FlowTestUtils.MATCH_ECHO_STEP)); Assert.assertNull(linear.findFirstMatch(nullNode, FlowTestUtils.MATCH_ECHO_STEP)); Assert.assertNull(linear.findFirstMatch(nullExecution, FlowTestUtils.MATCH_ECHO_STEP)); @@ -158,9 +158,9 @@ public void testAbstractScanner() throws Exception { // Filtered nodes FlowTestUtils.assertNodeOrder("Filtered echo nodes", linear.filteredNodes(heads, FlowTestUtils.MATCH_ECHO_STEP), 5, 4); FlowTestUtils.assertNodeOrder("Filtered echo nodes", linear.filteredNodes(heads, Collections.singleton(intermediateNode), FlowTestUtils.MATCH_ECHO_STEP), 5); - Assert.assertEquals(0, linear.filteredNodes(heads, null, (Predicate) Predicates.alwaysFalse()).size()); + Assert.assertEquals(0, linear.filteredNodes(heads, null, Predicates.alwaysFalse()).size()); Assert.assertEquals(0, linear.filteredNodes(nullNode, FlowTestUtils.MATCH_ECHO_STEP).size()); - Assert.assertEquals(0, linear.filteredNodes(Collections.EMPTY_SET, FlowTestUtils.MATCH_ECHO_STEP).size()); + Assert.assertEquals(0, linear.filteredNodes(Collections.emptySet(), FlowTestUtils.MATCH_ECHO_STEP).size()); // Same filter using the filterator linear.setup(heads); @@ -174,7 +174,7 @@ public void testAbstractScanner() throws Exception { // Visitor pattern tests FlowTestUtils.CollectingVisitor visitor = new FlowTestUtils.CollectingVisitor(); - linear.visitAll(Collections.EMPTY_SET, visitor); + linear.visitAll(Collections.emptySet(), visitor); Assert.assertEquals(0, visitor.getVisited().size()); visitor.reset(); @@ -287,7 +287,7 @@ public void testBasicScanWithBlock() throws Exception { // // Test block jump core FlowNode headCandidate = exec.getNode("8"); - Assert.assertEquals(exec.getNode("4"), linearBlockHoppingScanner.jumpBlockScan(headCandidate, Collections.EMPTY_SET)); + Assert.assertEquals(exec.getNode("4"), linearBlockHoppingScanner.jumpBlockScan(headCandidate, Collections.emptySet())); Assert.assertTrue("Setup should return true if we can iterate", linearBlockHoppingScanner.setup(headCandidate, null)); // Test the actual iteration diff --git a/src/test/java/org/jenkinsci/plugins/workflow/graphanalysis/FlowTestUtils.java b/src/test/java/org/jenkinsci/plugins/workflow/graphanalysis/FlowTestUtils.java index 59642ab3..56ea42f3 100644 --- a/src/test/java/org/jenkinsci/plugins/workflow/graphanalysis/FlowTestUtils.java +++ b/src/test/java/org/jenkinsci/plugins/workflow/graphanalysis/FlowTestUtils.java @@ -41,16 +41,13 @@ */ public class FlowTestUtils { public static Predicate predicateMatchStepDescriptor(@NonNull final String descriptorId) { - return new Predicate() { - @Override - public boolean apply(FlowNode input) { - if (input instanceof StepAtomNode) { - StepAtomNode san = (StepAtomNode)input; - StepDescriptor sd = san.getDescriptor(); - return sd != null && descriptorId.equals(sd.getId()); - } - return false; + return input -> { + if (input instanceof StepAtomNode) { + StepAtomNode san = (StepAtomNode)input; + StepDescriptor sd = san.getDescriptor(); + return sd != null && descriptorId.equals(sd.getId()); } + return false; }; } diff --git a/src/test/java/org/jenkinsci/plugins/workflow/graphanalysis/ForkScannerTest.java b/src/test/java/org/jenkinsci/plugins/workflow/graphanalysis/ForkScannerTest.java index fd686523..86f1da4b 100644 --- a/src/test/java/org/jenkinsci/plugins/workflow/graphanalysis/ForkScannerTest.java +++ b/src/test/java/org/jenkinsci/plugins/workflow/graphanalysis/ForkScannerTest.java @@ -49,6 +49,7 @@ import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashSet; @@ -70,7 +71,7 @@ public class ForkScannerTest { public static Predicate predicateForCallEntryType(final TestVisitor.CallType type) { return new Predicate() { - TestVisitor.CallType myType = type; + final TestVisitor.CallType myType = type; @Override public boolean test(TestVisitor.CallEntry input) { @@ -180,7 +181,7 @@ private void assertIncompleteParallelsHaveEventsForEnd(List heads, Tes // Verify we have at least one appropriate parallel end event, for the mandatory parallel List parallelEnds = test.filteredCallsByType(TestVisitor.CallType.PARALLEL_END).stream() - .map(CALL_TO_NODE_ID::apply) + .map(CALL_TO_NODE_ID) .collect(Collectors.toList()); boolean hasMatchingEnd = false; for (FlowNode f : heads) { @@ -193,7 +194,7 @@ private void assertIncompleteParallelsHaveEventsForEnd(List heads, Tes List branchEnds = test.filteredCallsByType(TestVisitor.CallType.PARALLEL_BRANCH_END).stream() - .map(CALL_TO_NODE_ID::apply) + .map(CALL_TO_NODE_ID) .collect(Collectors.toList()); // Verify each branch has a branch end event for (FlowNode f : heads) { @@ -204,7 +205,7 @@ private void assertIncompleteParallelsHaveEventsForEnd(List heads, Tes } /** Runs a fairly extensive suite of sanity tests of iteration and visitor use */ - private void sanityTestIterationAndVisiter(List heads) throws Exception { + private void sanityTestIterationAndVisiter(List heads) { ForkScanner scan = new ForkScanner(); TestVisitor test = new TestVisitor(); scan.setup(heads); @@ -278,7 +279,7 @@ public void testForkedScanner() throws Exception { Assert.assertNotNull(scanner.parallelBlockStartStack); Assert.assertEquals(0, scanner.parallelBlockStartStack.size()); Assert.assertEquals(exec.getNode("4"), scanner.currentParallelStartNode); - sanityTestIterationAndVisiter(Arrays.asList(exec.getNode("13"))); + sanityTestIterationAndVisiter(Collections.singletonList(exec.getNode("13"))); ForkScanner.ParallelBlockStart start = scanner.currentParallelStart; Assert.assertEquals(1, start.unvisited.size()); @@ -430,9 +431,9 @@ public void testEmptyParallel() throws Exception { Assert.assertEquals(9, outputs.size()); } - private Function NODE_TO_ID = input -> input != null ? input.getId() : null; + private final Function NODE_TO_ID = input -> input != null ? input.getId() : null; - private Function CALL_TO_NODE_ID = + private final Function CALL_TO_NODE_ID = input -> input != null && input.getNodeId() != null ? input.getNodeId().toString() @@ -518,7 +519,7 @@ public void testSingleNestedParallelBranches() throws Exception { FlowNode echoNode = new DepthFirstScanner().findFirstMatch(b.getExecution(), new NodeStepTypePredicate(EchoStep.DescriptorImpl.byFunctionName("echo"))); Assert.assertNotNull(echoNode); sanityTestIterationAndVisiter(b.getExecution().getCurrentHeads()); - sanityTestIterationAndVisiter(Arrays.asList(echoNode)); + sanityTestIterationAndVisiter(Collections.singletonList(echoNode)); TestVisitor visitor = new TestVisitor(); ForkScanner scanner = new ForkScanner(); @@ -547,7 +548,7 @@ public void testLeastCommonAncestor() throws Exception { Assert.assertArrayEquals(heads.toArray(), start.unvisited.toArray()); // Ensure no issues with single start triggering least common ancestor - heads = new LinkedHashSet<>(Arrays.asList(exec.getNode("4"))); + heads = new LinkedHashSet<>(Collections.singletonList(exec.getNode("4"))); scan.setup(heads); Assert.assertNull(scan.currentParallelStart); Assert.assertTrue(scan.parallelBlockStartStack == null || scan.parallelBlockStartStack.isEmpty()); @@ -707,7 +708,7 @@ public void testSimpleVisitor() throws Exception { FlowExecution exec = this.SIMPLE_PARALLEL_RUN.getExecution(); ForkScanner f = new ForkScanner(); f.setup(exec.getCurrentHeads()); - Assert.assertArrayEquals(new HashSet(exec.getCurrentHeads()).toArray(), new HashSet(f.currentParallelHeads()).toArray()); + Assert.assertArrayEquals(new HashSet<>(exec.getCurrentHeads()).toArray(), new HashSet<>(f.currentParallelHeads()).toArray()); List expectedHeads = f.currentParallelHeads(); sanityTestIterationAndVisiter(exec.getCurrentHeads()); diff --git a/src/test/java/org/jenkinsci/plugins/workflow/graphanalysis/TestVisitor.java b/src/test/java/org/jenkinsci/plugins/workflow/graphanalysis/TestVisitor.java index fcefa8da..f71f2325 100644 --- a/src/test/java/org/jenkinsci/plugins/workflow/graphanalysis/TestVisitor.java +++ b/src/test/java/org/jenkinsci/plugins/workflow/graphanalysis/TestVisitor.java @@ -59,9 +59,7 @@ public CallEntry(CallType type, FlowNode... nodes) { public CallEntry(CallType type, int... vals) { this.type = type; - for (int i=0; i filteredCallsByType(TestVisitor.CallType type /** Tests that the rules laid out in {@link SimpleChunkVisitor} javadocs are followed. * Specifically: no atomNode dupes for the same node, no atomNode with a start/end for the same node*/ - public void assertNoDupes() throws Exception { + public void assertNoDupes() { // Full equality check List entries = new ArrayList<>(); HashSet visitedAtomNodes = new HashSet<>(); @@ -236,7 +234,7 @@ public void assertNoDupes() throws Exception { /** Parallel callback events CANNOT have nulls for the parallel start node */ @Issue("JENKINS-39841") - public void assertNoIllegalNullsInEvents() throws Exception { + public void assertNoIllegalNullsInEvents() { for (CallEntry ce : calls) { Integer id = ce.getNodeId(); Assert.assertNotNull("Callback with illegally null node: "+ce, id); @@ -263,7 +261,7 @@ public void assertAllNodesGotChunkEvents(Iterable nodes) { } } - public void assertMatchingParallelBranchStartEnd() throws Exception { + public void assertMatchingParallelBranchStartEnd() { // Map the parallel start node to the start/end nodes for all branches HashMap> branchStartIds = new HashMap<>(); HashMap> branchEndIds = new HashMap<>(); @@ -308,7 +306,7 @@ public void assertMatchingParallelBranchStartEnd() throws Exception { } /** Verify that we have balanced start/end for parallels */ - public void assertMatchingParallelStartEnd() throws Exception { + public void assertMatchingParallelStartEnd() { // It's like balancing parentheses, starts and ends must be equal ArrayDeque openParallelStarts = new ArrayDeque<>(); @@ -334,7 +332,7 @@ public void assertMatchingParallelStartEnd() throws Exception { for (Integer parallelStartId : openParallelStarts) { sb.append(parallelStartId).append(','); } - Assert.fail("Parallel ends with no starts, for parallel(s) with start nodes IDs: "+sb.toString()); + Assert.fail("Parallel ends with no starts, for parallel(s) with start nodes IDs: " + sb); } } } diff --git a/src/test/java/org/jenkinsci/plugins/workflow/log/LogStorageTestBase.java b/src/test/java/org/jenkinsci/plugins/workflow/log/LogStorageTestBase.java index d5221237..69205a5c 100644 --- a/src/test/java/org/jenkinsci/plugins/workflow/log/LogStorageTestBase.java +++ b/src/test/java/org/jenkinsci/plugins/workflow/log/LogStorageTestBase.java @@ -28,6 +28,7 @@ import static org.hamcrest.Matchers.empty; import static org.junit.Assert.assertEquals; +import edu.umd.cs.findbugs.annotations.NonNull; import hudson.console.AnnotatedLargeText; import hudson.console.HyperlinkNote; import hudson.model.Action; @@ -309,11 +310,11 @@ private long assertLog(Callable> text, long start, String return pos; } - protected final void assertLength(long length) throws Exception { + protected final void assertLength(long length) { assertLength(text(), length); } - protected final void assertLength(String id, long length) throws Exception { + protected final void assertLength(String id, long length) { assertLength(text(id), length); } @@ -321,11 +322,11 @@ private void assertLength(AnnotatedLargeText text, long length) { assertEquals(length, text.length()); } - private AnnotatedLargeText text() throws Exception { + private AnnotatedLargeText text() { return createStorage().overallLog(null, true); } - private AnnotatedLargeText text(String id) throws Exception { + private AnnotatedLargeText text(String id) { return createStorage().stepLog(new MockNode(id), true); } @@ -370,6 +371,7 @@ public FlowNode getNode(String id) { throw new UnsupportedOperationException(); } + @NonNull @Override public Authentication getAuthentication() { throw new UnsupportedOperationException();