From eef3c224cb6cad4b82a96938ade1e42ca881eea2 Mon Sep 17 00:00:00 2001 From: eramkve Date: Fri, 16 Mar 2018 15:44:07 +0000 Subject: Fix all bugs reported by Sonar in policy/engine Code fixes for 27 bugs reported by Sonar in policy/engine Change-Id: I96da96b38a2e2954ec549e5cdf6ed3ad1d76722c Issue-ID: POLICY-662 Signed-off-by: eramkve --- .../policy/pdp/rest/api/services/GetDictionaryService.java | 2 +- .../org/onap/policy/pdp/rest/api/services/PDPServices.java | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'ONAP-PDP-REST/src/main/java') diff --git a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/GetDictionaryService.java b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/GetDictionaryService.java index d3628f3c1..9b86204e0 100644 --- a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/GetDictionaryService.java +++ b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/GetDictionaryService.java @@ -247,7 +247,7 @@ public class GetDictionaryService { jsonString = jsonString.replace("microServiceDictionaryDatas", "DictionaryDatas"); break; default: - return null; + break; } return jsonString; } diff --git a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PDPServices.java b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PDPServices.java index 8258aba1a..af7112ebd 100644 --- a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PDPServices.java +++ b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PDPServices.java @@ -341,12 +341,13 @@ public class PDPServices { pdpConfigLocation = pdpConfigLocation.replace("/", File.separator); } InputStream inputStream = null; + JsonReader jsonReader = null; try { inputStream = new FileInputStream(new File(pdpConfigLocation)); try { if (pdpConfigLocation.endsWith("json")) { pdpResponse.setType(PolicyType.JSON); - JsonReader jsonReader = Json.createReader(inputStream); + jsonReader = Json.createReader(inputStream); pdpResponse.setConfig(jsonReader.readObject().toString()); jsonReader.close(); } else if (pdpConfigLocation.endsWith("xml")) { @@ -400,6 +401,14 @@ public class PDPServices { LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); throw new PDPException(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Cannot open a connection to the configURL", e); + } finally { + if(jsonReader != null) { + try { + jsonReader.close(); + } catch (Exception e) { + LOGGER.error("Exception Occured while closing the JsonReader"+e); + } + } } } catch (FileNotFoundException e) { LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + e); -- cgit 1.2.3-korg