From f8b71bc84ba62e0bb2377fd1010c93cc3bb633b4 Mon Sep 17 00:00:00 2001 From: Christian Brauchmann Date: Thu, 19 Sep 2024 09:29:38 +0200 Subject: [PATCH] Fix: Fix npe for propagation url settings When upgrading from older versions of the plugin the propagationUrl tag might be missing in io.jenkins.plugins.bitbucketpushandpullrequest.config.BitBucketPPRPluginConfig.xml. Since propagationUrl's value is checked for emptiness only this might result in a NPE. This commit adds a check for null+emptiness. --- .../action/BitBucketPPRPullRequestServerAction.java | 2 +- .../config/BitBucketPPRPluginConfig.java | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/action/BitBucketPPRPullRequestServerAction.java b/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/action/BitBucketPPRPullRequestServerAction.java index 7bc59de..5636fe7 100644 --- a/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/action/BitBucketPPRPullRequestServerAction.java +++ b/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/action/BitBucketPPRPullRequestServerAction.java @@ -88,7 +88,7 @@ public BitBucketPPRPullRequestServerAction(@Nonnull BitBucketPPRPayload payload) } } - if (!globalConfig.getPropagationUrl().isEmpty()) { + if (globalConfig.isPropagationUrlSet()) { try { this.baseUrl = new URL(globalConfig.getPropagationUrl()); } catch (MalformedURLException e) { diff --git a/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/config/BitBucketPPRPluginConfig.java b/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/config/BitBucketPPRPluginConfig.java index 1928ef8..3bf9396 100644 --- a/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/config/BitBucketPPRPluginConfig.java +++ b/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/config/BitBucketPPRPluginConfig.java @@ -101,6 +101,10 @@ public String getPropagationUrl() { return propagationUrl; } + public boolean isPropagationUrlSet() { + return !isEmpty(propagationUrl); + } + @DataBoundSetter public void setNotifyBitBucket(@CheckForNull boolean notifyBitBucket) { this.notifyBitBucket = notifyBitBucket;