From 4c9bc0204405fc840cac190fb9e0de946f3899ff Mon Sep 17 00:00:00 2001 From: Parshad Patel Date: Thu, 19 Jul 2018 13:33:51 +0900 Subject: Fix use try-with-resources sonar issue Fix in ArtifactUuidFix.java Issue-ID: SDC-1529 Change-Id: Ic6438acbeebcbd5cdaa078a63700560563c518c6 Signed-off-by: Parshad Patel --- .../sdc/asdctool/impl/ArtifactUuidFix.java | 55 ++++------------------ 1 file changed, 8 insertions(+), 47 deletions(-) (limited to 'asdctool/src') diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/ArtifactUuidFix.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/ArtifactUuidFix.java index b44cd35729..fa02377623 100644 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/ArtifactUuidFix.java +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/ArtifactUuidFix.java @@ -133,10 +133,8 @@ public class ArtifactUuidFix { private boolean fetchFaultVf(String fixComponent, List vfLst, long time) { log.info("Find fault VF "); - Writer writer = null; - try { - String fileName = "fault_" + time + ".csv"; - writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), "utf-8")); + String fileName = "fault_" + time + ".csv"; + try(Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), "utf-8"))) { writer.write("vf name, vf id, state, version\n"); Map hasProps = new HashMap<>(); @@ -197,12 +195,6 @@ public class ArtifactUuidFix { return false; } finally { titanDao.commit(); - try { - writer.flush(); - writer.close(); - } catch (Exception ex) { - /* ignore */ - } } return true; } @@ -213,10 +205,8 @@ public class ArtifactUuidFix { log.info("No services as input"); return true; } - Writer writer = null; - try { - String fileName = "problemVf_" + time + ".csv"; - writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), "utf-8")); + String fileName = "problemVf_" + time + ".csv"; + try(Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), "utf-8"))) { writer.write("vf name, vf id, state, version, example service name\n"); Set vfIds = new HashSet<>(); for (Service service : serviceList) { @@ -253,23 +243,14 @@ public class ArtifactUuidFix { return false; } finally { titanDao.commit(); - try { - writer.flush(); - writer.close(); - } catch (Exception ex) { - /* ignore */ - } } return true; } private boolean fetchServices(String fixServices, List serviceList, long time) { log.info("Find problem Services {}", fixServices); - Writer writer = null; - - try { - String fileName = "problemService_" + time + ".csv"; - writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), "utf-8")); + String fileName = "problemService_" + time + ".csv"; + try(Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), "utf-8"))) { writer.write("service name, service id, state, version\n"); Map hasProps = new HashMap<>(); @@ -322,12 +303,6 @@ public class ArtifactUuidFix { return false; } finally { titanDao.commit(); - try { - writer.flush(); - writer.close(); - } catch (Exception ex) { - /* ignore */ - } } return true; } @@ -607,9 +582,7 @@ public class ArtifactUuidFix { long time = System.currentTimeMillis(); String fileName = "FailedGenerateTosca" + "_" + time + ".csv"; - Writer writer = null; - try { - writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), "utf-8")); + try(Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), "utf-8"))) { writer.write("componentType, name, version, UID, UUID, invariantUUID, state\n"); List failedList = new ArrayList<>(); @@ -693,11 +666,6 @@ public class ArtifactUuidFix { log.error(e.getMessage()); } finally { titanDao.commit(); - try { - writer.flush(); - writer.close(); - } catch (Exception ex) { - /* ignore */} } log.info(" Fix finished with res {} ***** ", res); return res; @@ -1163,9 +1131,7 @@ public class ArtifactUuidFix { boolean result = true; long time = System.currentTimeMillis(); String fileName = name + "_" + time + ".csv"; - Writer writer = null; - try { - writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), "utf-8")); + try(Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), "utf-8"))) { writer.write("name, UUID, invariantUUID, state, version\n"); for (Map.Entry> entry : vertices.entrySet()) { List compList = entry.getValue(); @@ -1214,11 +1180,6 @@ public class ArtifactUuidFix { return false; } finally { titanDao.commit(); - try { - writer.flush(); - writer.close(); - } catch (Exception ex) { - /* ignore */} } return result; } -- cgit 1.2.3-korg