Skip to content

Commit a0c6e1c

Browse files
authored
Merge pull request jenkinsci#43 from MRamonLeon/fix-spotbugs
Fix spotbugs warnings
2 parents 40359d3 + fc99dff commit a0c6e1c

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

src/main/java/com/cloudbees/jenkins/plugins/sshagent/jna/JNRRemoteAgentFactory.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import hudson.FilePath;
3333
import hudson.Launcher;
3434
import hudson.model.TaskListener;
35+
import hudson.remoting.VirtualChannel;
3536

3637
/**
3738
* A factory that uses the Apache Mina/SSH library support to natively provide a ssh-agent implementation on platforms
@@ -66,14 +67,18 @@ public boolean isSupported(Launcher launcher, final TaskListener listener) {
6667
public RemoteAgent start(LauncherProvider launcherProvider, final TaskListener listener, FilePath temp)
6768
throws Throwable {
6869

69-
if (launcherProvider == null || launcherProvider.getLauncher() == null){
70-
throw new IllegalStateException("RemoteLauncher has been initialized with a null launcher provider. It should not happen");
70+
Launcher launcher = (launcherProvider == null) ? null : launcherProvider.getLauncher();
71+
if (launcher == null){
72+
throw new IllegalStateException("RemoteLauncher has been initialized with a null launcher. It should not happen");
7173
}
7274

73-
RemoteHelper.registerBouncyCastle(launcherProvider.getLauncher().getChannel(), listener);
75+
VirtualChannel channel = launcher.getChannel();
76+
if (channel == null) {
77+
throw new IllegalStateException("RemoteLauncher has been initialized with null channel. It should not happen");
78+
}
79+
RemoteHelper.registerBouncyCastle(channel, listener);
7480

75-
return launcherProvider.getLauncher().getChannel().call(
76-
new JNRRemoteAgentStarter(listener, temp != null ? temp.getRemote() : null));
81+
return channel.call(new JNRRemoteAgentStarter(listener, temp != null ? temp.getRemote() : null));
7782
}
7883

7984
}

src/main/java/com/cloudbees/jenkins/plugins/sshagent/mina/MinaRemoteAgentFactory.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import hudson.FilePath;
3333
import hudson.Launcher;
3434
import hudson.model.TaskListener;
35+
import hudson.remoting.VirtualChannel;
3536
import jenkins.security.MasterToSlaveCallable;
3637
import org.apache.tomcat.jni.Library;
3738

@@ -54,11 +55,12 @@ public String getDisplayName() {
5455
*/
5556
@Override
5657
public boolean isSupported(Launcher launcher, final TaskListener listener) {
57-
if (launcher == null || launcher.getChannel() == null) {
58-
throw new IllegalStateException("RemoteLauncher has been initialized with null launcher. It should not happen");
58+
VirtualChannel channel = (launcher == null) ? null : launcher.getChannel();
59+
if (channel == null) {
60+
throw new IllegalStateException("RemoteLauncher has been initialized with null launcher/channel. It should not happen");
5961
}
6062
try {
61-
return launcher.getChannel().call(new TomcatNativeInstalled(listener));
63+
return channel.call(new TomcatNativeInstalled(listener));
6264
} catch (Throwable throwable) {
6365
return false;
6466
}
@@ -70,15 +72,19 @@ public boolean isSupported(Launcher launcher, final TaskListener listener) {
7072
@Override
7173
public RemoteAgent start(LauncherProvider launcherProvider, final TaskListener listener, FilePath temp)
7274
throws Throwable {
73-
74-
if (launcherProvider == null || launcherProvider.getLauncher() == null){
75-
throw new IllegalStateException("RemoteLauncher has been initialized with null launcher provider. It should not happen");
75+
Launcher launcher = (launcherProvider == null) ? null : launcherProvider.getLauncher();
76+
if (launcher == null){
77+
throw new IllegalStateException("RemoteLauncher has been initialized with null launcher. It should not happen");
7678
}
7779

78-
RemoteHelper.registerBouncyCastle(launcherProvider.getLauncher().getChannel(), listener);
80+
VirtualChannel channel = launcher.getChannel();
81+
if (channel == null) {
82+
throw new IllegalStateException("RemoteLauncher has been initialized with null channel. It should not happen");
83+
}
84+
RemoteHelper.registerBouncyCastle(channel, listener);
7985

8086
// TODO temp directory currently ignored
81-
return launcherProvider.getLauncher().getChannel().call(new MinaRemoteAgentStarter(listener));
87+
return channel.call(new MinaRemoteAgentStarter(listener));
8288
}
8389

8490
private static class TomcatNativeInstalled extends MasterToSlaveCallable<Boolean, Throwable> {

0 commit comments

Comments
 (0)