Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop using deprecated Util#join #855

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.nirima.jenkins.plugins.docker.DockerTemplateBase;
import hudson.EnvVars;
import hudson.FilePath;
import hudson.Util;
import hudson.model.Computer;
import hudson.model.Node;
import hudson.model.TaskListener;
Expand All @@ -31,6 +30,7 @@
import java.io.Serializable;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;

/**
* @author <a href="mailto:[email protected]">Nicolas De Loof</a>
Expand Down Expand Up @@ -193,7 +193,7 @@ private void invokeBody(DockerTransientNode node, TaskListener listener) {
env.overrideExpandingAll(computer.buildEnvironment(listener));
env.put("NODE_NAME", computer.getName());
env.put("EXECUTOR_NUMBER", "0");
env.put("NODE_LABELS", Util.join(node.getAssignedLabels(), " "));
env.put("NODE_LABELS", node.getAssignedLabels().stream().map(Object::toString).collect(Collectors.joining(" ")));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I'm unsure of the cause, it looks like this change breaks the unit-tests.

...also, I'm not a big fan of having so many method calls daisy-chained on the same line - it makes debugging a NPE nigh-on impossible.
I'd suggest implementing a join method (possibly in this plugin's utils package, maybe as a new class unless it fits well in another), and adding a unit-test for it (to prove it'll cope with a null input, or an input containing nulls, as well as normal non-null stuff), and then call that instead of Util.join.
I suspect that such a unit-test would then reveal that Util.join was more null-safe than this new code and fixing that would then fix the failing unit-tests.

env.put("WORKSPACE", ws.getRemote());
} catch (IOException | InterruptedException e) {
getContext().onFailure(e);
Expand Down