Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 8A061200C41 for ; Thu, 16 Feb 2017 19:00:53 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 88C95160B52; Thu, 16 Feb 2017 18:00:53 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id B0367160B72 for ; Thu, 16 Feb 2017 19:00:52 +0100 (CET) Received: (qmail 2042 invoked by uid 500); 16 Feb 2017 18:00:51 -0000 Mailing-List: contact commits-help@atlas.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@atlas.incubator.apache.org Delivered-To: mailing list commits@atlas.incubator.apache.org Received: (qmail 1914 invoked by uid 99); 16 Feb 2017 18:00:51 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 16 Feb 2017 18:00:51 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id 6E480C198A for ; Thu, 16 Feb 2017 18:00:51 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -6.219 X-Spam-Level: X-Spam-Status: No, score=-6.219 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-2.999] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id vGwpmaCrnSVh for ; Thu, 16 Feb 2017 18:00:50 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with SMTP id 36C8F5F36C for ; Thu, 16 Feb 2017 18:00:49 +0000 (UTC) Received: (qmail 1124 invoked by uid 99); 16 Feb 2017 18:00:48 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 16 Feb 2017 18:00:48 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 1326DDFC63; Thu, 16 Feb 2017 18:00:48 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: dkantor@apache.org To: commits@atlas.incubator.apache.org Message-Id: <7eebbebe47a14e9e80b8c7e9f50577da@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: incubator-atlas git commit: ATLAS-1539 Address coverity scan issues Date: Thu, 16 Feb 2017 18:00:48 +0000 (UTC) archived-at: Thu, 16 Feb 2017 18:00:53 -0000 Repository: incubator-atlas Updated Branches: refs/heads/master 20fb5894d -> 90f1566af ATLAS-1539 Address coverity scan issues Project: http://git-wip-us.apache.org/repos/asf/incubator-atlas/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-atlas/commit/90f1566a Tree: http://git-wip-us.apache.org/repos/asf/incubator-atlas/tree/90f1566a Diff: http://git-wip-us.apache.org/repos/asf/incubator-atlas/diff/90f1566a Branch: refs/heads/master Commit: 90f1566afabaec8aca5d87050eab43f56f911644 Parents: 20fb589 Author: Dave Kantor Authored: Thu Feb 16 13:00:38 2017 -0500 Committer: Dave Kantor Committed: Thu Feb 16 13:00:38 2017 -0500 ---------------------------------------------------------------------- .../apache/atlas/ApplicationPropertiesTest.java | 62 ++++++++++++++++---- 1 file changed, 52 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/90f1566a/common/src/test/java/org/apache/atlas/ApplicationPropertiesTest.java ---------------------------------------------------------------------- diff --git a/common/src/test/java/org/apache/atlas/ApplicationPropertiesTest.java b/common/src/test/java/org/apache/atlas/ApplicationPropertiesTest.java index cddf974..89e5e9b 100644 --- a/common/src/test/java/org/apache/atlas/ApplicationPropertiesTest.java +++ b/common/src/test/java/org/apache/atlas/ApplicationPropertiesTest.java @@ -32,23 +32,52 @@ public class ApplicationPropertiesTest { @Test public void testGetFileAsInputStream() throws Exception { Configuration props = ApplicationProperties.get("test.properties"); + InputStream inStr = null; // configured file as class loader resource - InputStream inStr = ApplicationProperties.getFileAsInputStream(props, "jaas.properties.file", null); - assertNotNull(inStr); + try { + inStr = ApplicationProperties.getFileAsInputStream(props, "jaas.properties.file", null); + assertNotNull(inStr); + } + finally { + if (inStr != null) { + inStr.close(); + } + } // configured file from file system path props.setProperty("jaas.properties.file", "src/test/resources/atlas-jaas.properties"); - inStr = ApplicationProperties.getFileAsInputStream(props, "jaas.properties.file", null); - assertNotNull(inStr); + try { + inStr = ApplicationProperties.getFileAsInputStream(props, "jaas.properties.file", null); + assertNotNull(inStr); + } + finally { + if (inStr != null) { + inStr.close(); + } + } // default file as class loader resource - inStr = ApplicationProperties.getFileAsInputStream(props, "property.not.specified.in.config", "atlas-jaas.properties"); - assertNotNull(inStr); + try { + inStr = ApplicationProperties.getFileAsInputStream(props, "property.not.specified.in.config", "atlas-jaas.properties"); + assertNotNull(inStr); + } + finally { + if (inStr != null) { + inStr.close(); + } + } // default file relative to working directory - inStr = ApplicationProperties.getFileAsInputStream(props, "property.not.specified.in.config", "src/test/resources/atlas-jaas.properties"); - assertNotNull(inStr); + try { + inStr = ApplicationProperties.getFileAsInputStream(props, "property.not.specified.in.config", "src/test/resources/atlas-jaas.properties"); + assertNotNull(inStr); + } + finally { + if (inStr != null) { + inStr.close(); + } + } // default file relative to atlas configuration directory String originalConfDirSetting = System.setProperty(ApplicationProperties.ATLAS_CONFIGURATION_DIRECTORY_PROPERTY, "src/test/resources"); @@ -57,6 +86,9 @@ public class ApplicationPropertiesTest { assertNotNull(inStr); } finally { + if (inStr != null) { + inStr.close(); + } if (originalConfDirSetting != null) { System.setProperty(ApplicationProperties.ATLAS_CONFIGURATION_DIRECTORY_PROPERTY, originalConfDirSetting); } @@ -67,21 +99,31 @@ public class ApplicationPropertiesTest { // non-existent property and no default file try { - ApplicationProperties.getFileAsInputStream(props, "property.not.specified.in.config", null); + inStr = ApplicationProperties.getFileAsInputStream(props, "property.not.specified.in.config", null); fail("Expected " + AtlasException.class.getSimpleName() + " but none thrown"); } catch (AtlasException e) { // good } + finally { + if (inStr != null) { + inStr.close(); + } + } // configured file not found in file system or classpath props.setProperty("jaas.properties.file", "does_not_exist.txt"); try { - ApplicationProperties.getFileAsInputStream(props, "jaas.properties.file", null); + inStr = ApplicationProperties.getFileAsInputStream(props, "jaas.properties.file", null); fail("Expected " + AtlasException.class.getSimpleName() + " but none thrown"); } catch (AtlasException e) { // good } + finally { + if (inStr != null) { + inStr.close(); + } + } } }