From 730394dcfbc41a0142b2c3649e673579fb891a6d Mon Sep 17 00:00:00 2001 From: Arindam Mondal Date: Tue, 10 Mar 2020 12:07:39 +0900 Subject: Sonar fix tr-with-resources Issue-ID: OPTFRA-714 Sonar link: https://sonar.onap.org/code?id=org.onap.fgps%3Afgps&selected=org.onap.fgps%3Afgps-api%3Asrc%2Fmain%2Fjava%2Forg%2Fonap%2Ffgps%2Fapi%2Feelf%2Fconfiguration%2FEELFManager.java Use try with resources Change-Id: I9f5fafa6c8511b8aed4293f93a0853a9b7dcdd62 Signed-off-by: arindamm --- .../onap/fgps/api/eelf/configuration/EELFManager.java | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/valetapi/src/main/java/org/onap/fgps/api/eelf/configuration/EELFManager.java b/valetapi/src/main/java/org/onap/fgps/api/eelf/configuration/EELFManager.java index feb98f9..a096748 100644 --- a/valetapi/src/main/java/org/onap/fgps/api/eelf/configuration/EELFManager.java +++ b/valetapi/src/main/java/org/onap/fgps/api/eelf/configuration/EELFManager.java @@ -312,24 +312,15 @@ public final class EELFManager { String msg = EELFResourceManager.getMessage(EELFMsgs.LOADING_LOG_CONFIGURATION,file.getAbsolutePath()); delayedLogging.add(msg); - BufferedInputStream stream = null; - try { - stream = new BufferedInputStream(new FileInputStream(file)); + try (BufferedInputStream stream = new BufferedInputStream(new FileInputStream(file));){ delayedLogging.add(String.format("EELF000I Loading logging configuration from %s", file.getAbsolutePath())); loadLoggingConfiguration(stream, delayedLogging); } catch (FileNotFoundException e) { delayedLogging.add(EELFResourceManager.format(e)); - } finally { - if (stream != null) { - try { - stream.close(); - } catch (IOException e) { - // not much we can do since logger may not be configured yet - e.printStackTrace(System.out); - } - } - } + } catch (IOException e1) { + delayedLogging.add(EELFResourceManager.format(e1)); + } return true; } -- cgit 1.2.3-korg