summaryrefslogtreecommitdiffstats
path: root/rulemgt/src/main/java/org
diff options
context:
space:
mode:
authorKrishnajinka <kris.jinka@samsung.com>2018-07-20 17:49:44 +0900
committerKrishnajinka <kris.jinka@samsung.com>2018-07-20 17:50:12 +0900
commitddccff7b5d1dee0a17afb4d1e63302cb99626c31 (patch)
tree67c561a40531aa63f56d52d61cb434dbc4063d9d /rulemgt/src/main/java/org
parent8e7f35e2f127d5b2c3691751742dc12c4fba4550 (diff)
FIX SONAR ISSUE USING TRY WITH RES
swagger resource file contain try blocks use try with resources construct as per SONAR Issue-ID: HOLMES-145 Change-Id: Id977d6d7b70698b965b32a67c31e366e510e11e0 Signed-off-by: Krishnajinka <kris.jinka@samsung.com>
Diffstat (limited to 'rulemgt/src/main/java/org')
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/SwaggerResource.java27
1 files changed, 9 insertions, 18 deletions
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/SwaggerResource.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/SwaggerResource.java
index 8376daf..83555b2 100644
--- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/SwaggerResource.java
+++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/SwaggerResource.java
@@ -18,11 +18,8 @@ package org.onap.holmes.rulemgt.resources;
import io.swagger.annotations.Api;
import io.swagger.annotations.SwaggerDefinition;
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.IOException;
+
+import java.io.*;
import java.net.URL;
import java.net.URLDecoder;
import javax.ws.rs.GET;
@@ -44,12 +41,15 @@ public class SwaggerResource {
URL url = SwaggerResource.class.getResource("/swagger.json");
String ret = "{}";
- BufferedReader br = null;
+ File file;
try {
System.out.println(URLDecoder.decode(url.getPath(), "UTF-8"));
- File file = new File(URLDecoder.decode(url.getPath(), "UTF-8"));
-
- br = new BufferedReader(new FileReader(file));
+ file = new File(URLDecoder.decode(url.getPath(), "UTF-8"));
+ } catch(IOException e) {
+ log.warn("An error occurred while reading swagger.json.", e);
+ return ret;
+ }
+ try(BufferedReader br = new BufferedReader(new FileReader(file));) {
StringBuffer buffer = new StringBuffer();
String line = " ";
while ((line = br.readLine()) != null) {
@@ -60,16 +60,7 @@ public class SwaggerResource {
log.warn("Failed to read the API description file.", e);
} catch (IOException e) {
log.warn("An error occurred while reading swagger.json.", e);
- } finally {
- if (br != null) {
- try {
- br.close();
- } catch (IOException e) {
- log.warn("Failed to close the file reader. This may cause memory leak.");
- }
- }
}
-
return ret;
}
}