title: Close/Destroy JIRA connection JAVA
body: <p>I'm a beginner in Java coding.
  Below is the code</p>
  <pre><code>public class AddJIRATicketWatcherCommandHandler {
  
  private final JiraFactory jiraFactory;
  
  public void handle(String jiraIssueKey, String watcher) {
      
          log.debug(&quot;Adding {} watcher to JIRA issue: {}&quot;, watcher, jiraIssueKey);
  
          final Issue issue = jiraFactory.createClient().getIssueClient().getIssue(jiraIssueKey).claim();
          log.debug(&quot;Found JIRA issue: {}&quot;, issue.getKey());
  
          Promise&lt;Void&gt; addWatcherPromise = jiraFactory.createClient().getIssueClient().addWatcher(issue.getWatchers().getSelf() , watcher);
          addWatcherPromise.claim();
   }}
  
  
  
  
  public JiraRestClient createClient() {
      log.debug(&quot;Creating JIRA rest client for remote environment&quot;);
  
      URI jiraServerUri = URI.create(&quot;&quot;);
  
      jiraServerUri = new URI(StringUtils.removeEnd(jiraConfig.getJiraURI(), &quot;/rest&quot;));
  
      JiraRestClient restClient = new AsynchronousJiraRestClientFactory().createWithBasicHttpAuthentication(jiraServerUri,
              jiraConfig.getJiraUsername(),
              jiraConfig.getJiraPassword());
  
      JIRA_LOGGER.info(&quot;url=[{}], username=[{}], password=[{}]&quot;, jiraServerUri.toString(), jiraConfig.getJiraUsername(), jiraConfig.getJiraPassword());
      log.debug(&quot;JIRA rest client created successfully for remote environment&quot;);
      return restClient;
  }
  </code></pre>
  <p>However, when I ran the sonarqube. I received this error.</p>
  <p>Use try-with-resources or close this &quot;JiraRestClient&quot; in a &quot;finally&quot; clause.</p>
  <p><a href="https://i.stack.imgur.com/aYn6R.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aYn6R.png" alt="enter image description here" /></a></p>
  <p>My understanding is to close the connection once done. But, I'm unsure on how to do that.</p>
  <p>I tried to implement finally with close(). But the results is still showing the same error.</p>
  <p><a href="https://i.stack.imgur.com/4qyTk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4qyTk.png" alt="enter image description here" /></a></p>