This is an automated email from the ASF dual-hosted git repository.

gnodet pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git

commit f6b309eaa894327ae1c15303ad725286548869b2
Author: Guillaume Nodet <gno...@gmail.com>
AuthorDate: Thu May 2 16:28:56 2024 +0200

    Fix jira double check locking
---
 .../apache/camel/component/jira/JiraEndpoint.java  | 64 ++++++++++------------
 1 file changed, 29 insertions(+), 35 deletions(-)

diff --git 
a/components/camel-jira/src/main/java/org/apache/camel/component/jira/JiraEndpoint.java
 
b/components/camel-jira/src/main/java/org/apache/camel/component/jira/JiraEndpoint.java
index 2be8eefcf14..f8da482ed8d 100644
--- 
a/components/camel-jira/src/main/java/org/apache/camel/component/jira/JiraEndpoint.java
+++ 
b/components/camel-jira/src/main/java/org/apache/camel/component/jira/JiraEndpoint.java
@@ -77,9 +77,7 @@ import static 
org.apache.camel.component.jira.JiraConstants.JIRA_REST_CLIENT_FAC
              category = { Category.DOCUMENT }, headersClass = 
JiraConstants.class)
 public class JiraEndpoint extends DefaultEndpoint {
 
-    private static final transient Logger LOG = 
LoggerFactory.getLogger(JiraEndpoint.class);
-
-    private final Object lock = new Object();
+    private static final Logger LOG = 
LoggerFactory.getLogger(JiraEndpoint.class);
 
     @UriPath
     @Metadata(required = true)
@@ -118,43 +116,39 @@ public class JiraEndpoint extends DefaultEndpoint {
         disconnect();
     }
 
-    public void connect() {
+    public synchronized void connect() {
         if (client == null) {
-            synchronized (lock) {
-                if (client == null) {
-                    Registry registry = getCamelContext().getRegistry();
-                    JiraRestClientFactory factory
-                            = 
registry.lookupByNameAndType(JIRA_REST_CLIENT_FACTORY, 
JiraRestClientFactory.class);
-                    if (factory == null) {
-                        factory = new OAuthAsynchronousJiraRestClientFactory();
-                    }
-                    final URI jiraServerUri = 
URI.create(configuration.getJiraUrl());
-                    if (configuration.getUsername() != null) {
-                        LOG.debug("Connecting to JIRA with Basic 
authentication with username/password");
-                        client = 
factory.createWithBasicHttpAuthentication(jiraServerUri, 
configuration.getUsername(),
-                                configuration.getPassword());
-                    } else if (configuration.getAccessToken() != null
-                            && configuration.getVerificationCode() == null
-                            && configuration.getPrivateKey() == null
-                            && configuration.getConsumerKey() == null) {
-                        client = factory.create(jiraServerUri, builder -> {
-                            builder.setHeader("Authorization", "Bearer " + 
configuration.getAccessToken());
-                        });
-                    } else {
-                        LOG.debug("Connecting to JIRA with OAuth 
authentication");
-                        JiraOAuthAuthenticationHandler oAuthHandler = new 
JiraOAuthAuthenticationHandler(
-                                configuration.getConsumerKey(),
-                                configuration.getVerificationCode(), 
configuration.getPrivateKey(),
-                                configuration.getAccessToken(),
-                                configuration.getJiraUrl());
-                        client = factory.create(jiraServerUri, oAuthHandler);
-                    }
-                }
+            Registry registry = getCamelContext().getRegistry();
+            JiraRestClientFactory factory
+                    = registry.lookupByNameAndType(JIRA_REST_CLIENT_FACTORY, 
JiraRestClientFactory.class);
+            if (factory == null) {
+                factory = new OAuthAsynchronousJiraRestClientFactory();
+            }
+            final URI jiraServerUri = URI.create(configuration.getJiraUrl());
+            if (configuration.getUsername() != null) {
+                LOG.debug("Connecting to JIRA with Basic authentication with 
username/password");
+                client = 
factory.createWithBasicHttpAuthentication(jiraServerUri, 
configuration.getUsername(),
+                        configuration.getPassword());
+            } else if (configuration.getAccessToken() != null
+                    && configuration.getVerificationCode() == null
+                    && configuration.getPrivateKey() == null
+                    && configuration.getConsumerKey() == null) {
+                client = factory.create(jiraServerUri, builder -> {
+                    builder.setHeader("Authorization", "Bearer " + 
configuration.getAccessToken());
+                });
+            } else {
+                LOG.debug("Connecting to JIRA with OAuth authentication");
+                JiraOAuthAuthenticationHandler oAuthHandler = new 
JiraOAuthAuthenticationHandler(
+                        configuration.getConsumerKey(),
+                        configuration.getVerificationCode(), 
configuration.getPrivateKey(),
+                        configuration.getAccessToken(),
+                        configuration.getJiraUrl());
+                client = factory.create(jiraServerUri, oAuthHandler);
             }
         }
     }
 
-    public void disconnect() throws Exception {
+    public synchronized void disconnect() throws Exception {
         if (client != null) {
             LOG.debug("Disconnecting from JIRA");
             client.close();

Reply via email to