aboutsummaryrefslogtreecommitdiffstats
path: root/appc-client/code-generator/src/main
diff options
context:
space:
mode:
authorSummers, Gregory (gs2953) <gs2953@att.com>2017-09-26 16:12:27 -0500
committerSkip Wonnell <skip@att.com>2017-09-27 12:56:11 +0000
commit9823cdb68b01c697a0ce0728eb32d7ad9fb32c66 (patch)
treeaf71d4c002fb4c8cd1d99595266b2c6be9ba1d17 /appc-client/code-generator/src/main
parent679dbdae2e7bf948de10031619ba65f573ba0267 (diff)
Fix Sonar blocker issue for resource leak
Issue-ID: APPC-186 Change-Id: I6177d3976e4e91a6f29bee21558dc603aed44f1f Signed-off-by: Summers, Gregory (gs2953) <gs2953@att.com>
Diffstat (limited to 'appc-client/code-generator/src/main')
-rw-r--r--appc-client/code-generator/src/main/java/org/openecomp/appc/tools/generator/extensions/YangContextBuilderImpl.java21
1 files changed, 10 insertions, 11 deletions
diff --git a/appc-client/code-generator/src/main/java/org/openecomp/appc/tools/generator/extensions/YangContextBuilderImpl.java b/appc-client/code-generator/src/main/java/org/openecomp/appc/tools/generator/extensions/YangContextBuilderImpl.java
index 32846166e..8325ecb6d 100644
--- a/appc-client/code-generator/src/main/java/org/openecomp/appc/tools/generator/extensions/YangContextBuilderImpl.java
+++ b/appc-client/code-generator/src/main/java/org/openecomp/appc/tools/generator/extensions/YangContextBuilderImpl.java
@@ -39,36 +39,35 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
-import java.util.*;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Set;
public class YangContextBuilderImpl implements ContextBuilder {
@Override
public Map<String, Object> buildContext(String sourceFile, String contextConf) throws FileNotFoundException {
- InputStream source = new FileInputStream(sourceFile);
- if (source == null) {
+ try ( InputStream source = new FileInputStream(sourceFile) ) {}
+ catch ( IOException ex) {
throw new FileNotFoundException("YANG file <" + sourceFile + ">not found");
}
- YangTextSchemaContextResolver yangContextResolver = YangTextSchemaContextResolver
- .create("yang-context-resolver");
- try {
+ Optional<SchemaContext> sc = null;
+ try ( YangTextSchemaContextResolver yangContextResolver =
+ YangTextSchemaContextResolver.create("yang-context-resolver")) {
yangContextResolver.registerSource(new URL("file:///" + sourceFile));
+ sc = yangContextResolver.getSchemaContext();
} catch (SchemaSourceException | IOException | YangSyntaxErrorException e) {
- // TODO Auto-generated catch block
e.printStackTrace();
}
- Optional<SchemaContext> sc = yangContextResolver.getSchemaContext();
Map<String, Object> map = new HashMap<>();
- if (sc.isPresent()) {
-
+ if ( null != sc && sc.isPresent()) {
Set<Module> modules = sc.get().getModules();
for (Module module : modules) {
ModuleEffectiveStatementImpl impl = (ModuleEffectiveStatementImpl) module;
map.put("module", module);
}
-
}
return map;