Sonar blocker issue - NullPointerExeption 97/28597/1
authorZhu Libo <libo.zhu@intel.com>
Wed, 17 Jan 2018 17:43:44 +0000 (01:43 +0800)
committerliboNet <libo.zhu@intel.com>
Fri, 19 Jan 2018 17:40:45 +0000 (01:40 +0800)
use the try-with-resource statement method to fix issues:
https://sonar.onap.org/issues/search#issues=AV3BnuCb5bp_wwmIVClC
and https://sonar.onap.org/issues/search#issues=AV7t547AlaLbmlVXT_jY

Change-Id: I912be949793066bef6e3036fb474247d4d269e4f
Issue-ID: SO-165
Signed-off-by: Zhu Libo <libo.zhu@intel.com>
adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/BpelRestClient.java

index a818992..749b9f9 100644 (file)
@@ -256,13 +256,9 @@ public class BpelRestClient {
                        .build();
                post.setConfig(requestConfig);
 
-               //Client 4.3+
-               CloseableHttpClient client = null;
-                               
         //Client 4.3+
         //Execute & GetResponse
-               try {
-                       client = HttpClients.createDefault();
+               try(CloseableHttpClient client = HttpClients.createDefault()) {
                        CloseableHttpResponse response = client.execute(post);
                        if (response != null) {
                                lastResponseCode = response.getStatusLine().getStatusCode();
@@ -277,16 +273,6 @@ public class BpelRestClient {
                        LOGGER.error (MessageEnum.RA_SEND_VNF_NOTIF_ERR, error, "Camunda", "", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - Error sending Bpel notification", e);
                        lastResponseCode = 900;
                        lastResponse = "";
-               } finally {
-                       try {
-                               client.close();
-                       } catch (IOException e) {
-                               // ignore
-                               LOGGER.debug("IOException: ", e);
-                       } catch (NullPointerException e) {
-                               //ignore
-                               LOGGER.debug("NullPointerException: ", e);
-                       }
                }
                LOGGER.debug("Response code from BPEL server: "+lastResponseCode);
                LOGGER.debug("Response body is: "+lastResponse);