Skip to content

Commit

Permalink
GearmanProxy: please spotbugs NPE for getComputer("")
Browse files Browse the repository at this point in the history
The Jenkins getComputer() method can return `null` when the requested
name does not match any Computer. There is always an unamed Computer
which is the built-in node and the method would never return `null` in
that case.

Addresses spotbugs NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE
  • Loading branch information
hashar committed Jan 17, 2022
1 parent 0f984f1 commit 595f444
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/main/java/hudson/plugins/gearman/GearmanProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,19 @@ private GearmanProxy() {
// query Jenkins for built-in name
try {
builtInNode = Jenkins.get().getComputer("");
hostname = builtInNode.getHostName();
if (builtInNode != null) {
hostname = builtInNode.getHostName();
} else {
// Built-in node may not be enabled so get builtInName from system
try {
hostname = java.net.InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException e) {
logger.warn("Exception while getting built-in node hostname", e);
}
}
} catch (Exception e) {
logger.warn("Exception while getting hostname", e);
}
// Built-in node may not be enabled so get builtInName from system
if (builtInNode == null) {
try {
hostname = java.net.InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException e) {
logger.warn("Exception while getting hostname", e);
}
}

builtInName = hostname;
}
Expand Down

0 comments on commit 595f444

Please sign in to comment.