Fix all bugs reported by Sonar in policy/engine
[policy/engine.git] / ONAP-PAP-REST / src / main / java / org / onap / policy / pap / xacml / rest / components / CreateBrmsRawPolicy.java
index a6240e0..0bac0e0 100644 (file)
@@ -72,15 +72,13 @@ public class CreateBrmsRawPolicy extends Policy {
 
        // Saving the Configurations file at server location for CreateBrmsRawPolicy policy.
        protected void saveConfigurations(String policyName, String jsonBody) {         
-               try {
-                       if (policyName.endsWith(".xml")) {
-                               policyName = policyName.substring(0,
-                                               policyName.lastIndexOf(".xml"));
-                       }
-                       PrintWriter out = new PrintWriter(CONFIG_HOME + File.separator + policyName + ".txt");
+           
+               if (policyName.endsWith(".xml")) {
+                   policyName = policyName.substring(0,
+                               policyName.lastIndexOf(".xml"));
+               }
+               try (PrintWriter out = new PrintWriter(CONFIG_HOME + File.separator + policyName + ".txt")){
                        out.println(jsonBody);
-                       out.close();
-
                } catch (Exception e) {
                        PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "CreateBrmsRawPolicy", "Exception saving configurations file");
                }