From 970d0c6a7ee9941090beb9ba9e07da1309b95219 Mon Sep 17 00:00:00 2001 From: Allan Burdajewicz Date: Wed, 15 May 2024 21:58:12 +1000 Subject: [PATCH] [JENKINS-72622] Address SpotBugs warning --- core/src/main/java/jenkins/agents/CloudSet.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/jenkins/agents/CloudSet.java b/core/src/main/java/jenkins/agents/CloudSet.java index 8846487a19440..aab5c2052b066 100644 --- a/core/src/main/java/jenkins/agents/CloudSet.java +++ b/core/src/main/java/jenkins/agents/CloudSet.java @@ -244,7 +244,11 @@ private void handleNewCloudPage(Descriptor descriptor, String name, Stapl public synchronized void doDoCreate(StaplerRequest req, StaplerResponse rsp, @QueryParameter String cloudDescriptorName) throws IOException, ServletException, Descriptor.FormException { Jenkins.get().checkPermission(Jenkins.ADMINISTER); - Cloud cloud = Cloud.all().findByName(cloudDescriptorName).newInstance(req, req.getSubmittedForm()); + Descriptor cloudDescriptor = Cloud.all().findByName(cloudDescriptorName); + if (cloudDescriptor == null) { + throw new Failure(String.format("No cloud descriptor found for %s", cloudDescriptorName)); + } + Cloud cloud = cloudDescriptor.newInstance(req, req.getSubmittedForm()); if (!Jenkins.get().clouds.add(cloud)) { LOGGER.log(Level.WARNING, () -> "Creating duplicate cloud name " + cloud.name + ". Plugin " + Jenkins.get().getPluginManager().whichPlugin(cloud.getClass()) + " should be updated to support user provided name."); }