From 943ccfedef0cfd8896814db203646e3e4de8cf8f Mon Sep 17 00:00:00 2001 From: Alan Jackoway Date: Mon, 12 Oct 2015 15:30:20 -0700 Subject: [PATCH] NIFI-1035 AbstractKiteProcessor.getSchema leaks file handles. closes #101. Close file handles when reading schema from resources or paths in AbstractKiteProcessor.getSchema Signed-off-by: joewitt --- .../nifi/processors/kite/AbstractKiteProcessor.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/nifi-nar-bundles/nifi-kite-bundle/nifi-kite-processors/src/main/java/org/apache/nifi/processors/kite/AbstractKiteProcessor.java b/nifi-nar-bundles/nifi-kite-bundle/nifi-kite-processors/src/main/java/org/apache/nifi/processors/kite/AbstractKiteProcessor.java index da1c046725..f90c089244 100644 --- a/nifi-nar-bundles/nifi-kite-bundle/nifi-kite-processors/src/main/java/org/apache/nifi/processors/kite/AbstractKiteProcessor.java +++ b/nifi-nar-bundles/nifi-kite-bundle/nifi-kite-processors/src/main/java/org/apache/nifi/processors/kite/AbstractKiteProcessor.java @@ -121,14 +121,17 @@ abstract class AbstractKiteProcessor extends AbstractProcessor { if ("dataset".equals(uri.getScheme()) || "view".equals(uri.getScheme())) { return Datasets.load(uri).getDataset().getDescriptor().getSchema(); } else if ("resource".equals(uri.getScheme())) { - InputStream in = Resources.getResource(uri.getSchemeSpecificPart()) - .openStream(); - return parseSchema(uri, in); + try (InputStream in = Resources.getResource(uri.getSchemeSpecificPart()) + .openStream()) { + return parseSchema(uri, in); + } } else { // try to open the file Path schemaPath = new Path(uri); FileSystem fs = schemaPath.getFileSystem(conf); - return parseSchema(uri, fs.open(schemaPath)); + try (InputStream in = fs.open(schemaPath)) { + return parseSchema(uri, in); + } } } catch (DatasetNotFoundException e) {