From 9c24d662337f0c2043fbd8e6dc7a91fb2b299dff Mon Sep 17 00:00:00 2001 From: Lianhao Lu Date: Fri, 12 Apr 2019 08:53:46 +0800 Subject: Fix sonnar issues Change-Id: Ic9ad2d733ace26fdd085a03af901783192d72a79 Issue-ID: POLICY-1638 Signed-off-by: Lianhao Lu --- .../policy/distribution/forwarding/file/FilePolicyForwarder.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'plugins/forwarding-plugins/src/main') diff --git a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/file/FilePolicyForwarder.java b/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/file/FilePolicyForwarder.java index 4115bff3..d02d9bba 100644 --- a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/file/FilePolicyForwarder.java +++ b/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/file/FilePolicyForwarder.java @@ -88,9 +88,8 @@ public class FilePolicyForwarder implements PolicyForwarder { */ private void forwardPolicy(final OptimizationPolicy pol) throws PolicyForwardingException { final String name = pol.getPolicyName(); - try { - Path path = Paths.get(fileForwarderParameters.getPath(), name); - BufferedWriter writer = new BufferedWriter(new FileWriter(path.toString())); + Path path = Paths.get(fileForwarderParameters.getPath(), name); + try (BufferedWriter writer = new BufferedWriter(new FileWriter(path.toString()))) { writer.write("policyName: " + name); if (fileForwarderParameters.isVerbose()) { writer.newLine(); @@ -112,7 +111,6 @@ public class FilePolicyForwarder implements PolicyForwarder { writer.newLine(); writer.write("riskType: " + pol.getRiskType()); } - writer.close(); LOGGER.debug("Sucessfully forwarded the policy to store into file {}.", path); } catch (final InvalidPathException | IOException exp) { final String message = "Error sending policy to file under path:" + fileForwarderParameters.getPath(); -- cgit 1.2.3-korg