[rhq] Branch 'code-smell' - 4 commits - modules/enterprise
by mazz
modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/Version.java | 6 +
modules/enterprise/agentupdate/src/main/java/org/rhq/enterprise/agent/update/AgentUpdate.java | 10 +-
modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/Version.java | 6 +
modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/commands/ScriptCommand.java | 42 +++++-----
4 files changed, 42 insertions(+), 22 deletions(-)
New commits:
commit 199940ca403f4123a2a6a753b196a12f975e207a
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Thu Jul 28 16:24:39 2011 -0400
[coverity] close jar file
diff --git a/modules/enterprise/agentupdate/src/main/java/org/rhq/enterprise/agent/update/AgentUpdate.java b/modules/enterprise/agentupdate/src/main/java/org/rhq/enterprise/agent/update/AgentUpdate.java
index fc43008..704b48d 100644
--- a/modules/enterprise/agentupdate/src/main/java/org/rhq/enterprise/agent/update/AgentUpdate.java
+++ b/modules/enterprise/agentupdate/src/main/java/org/rhq/enterprise/agent/update/AgentUpdate.java
@@ -272,9 +272,13 @@ public class AgentUpdate {
private byte[] getJarFileContent(String filename) throws Exception {
JarFile jarFile = new JarFile(getJarFilename()); // use the jar file because user might have used --jar
- JarEntry jarFileEntry = jarFile.getJarEntry(filename);
- InputStream jarFileEntryStream = jarFile.getInputStream(jarFileEntry);
- return slurp(jarFileEntryStream);
+ try {
+ JarEntry jarFileEntry = jarFile.getJarEntry(filename);
+ InputStream jarFileEntryStream = jarFile.getInputStream(jarFileEntry);
+ return slurp(jarFileEntryStream);
+ } finally {
+ jarFile.close();
+ }
}
private void printSyntax() {
commit 9cabd191fd42b89a86d1fa6bd2290bc5ea7a16c3
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Thu Jul 28 16:22:35 2011 -0400
[coverity] close reader
diff --git a/modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/commands/ScriptCommand.java b/modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/commands/ScriptCommand.java
index 693885f..9a071b7 100644
--- a/modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/commands/ScriptCommand.java
+++ b/modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/commands/ScriptCommand.java
@@ -58,7 +58,7 @@ public class ScriptCommand implements ClientCommand {
private ScriptEngine jsEngine;
private StandardBindings bindings;
-
+
private final Log log = LogFactory.getLog(ScriptCommand.class);
private StringBuilder script = new StringBuilder();
@@ -85,7 +85,15 @@ public class ScriptCommand implements ClientCommand {
bindScriptArgs(scriptCmdLine);
executeUtilScripts();
- return executeScriptFile(new FileReader(scriptCmdLine.getScriptFileName()), client);
+ FileReader reader = new FileReader(scriptCmdLine.getScriptFileName());
+ try {
+ return executeScriptFile(reader, client);
+ } finally {
+ try {
+ reader.close();
+ } catch (IOException ignore) {
+ }
+ }
} catch (FileNotFoundException e) {
client.getPrintWriter().println(e.getMessage());
if (log.isDebugEnabled()) {
@@ -97,8 +105,7 @@ public class ScriptCommand implements ClientCommand {
if (log.isDebugEnabled()) {
log.debug("A parse error occurred.", e);
}
- }
- else {
+ } else {
throw new CLIScriptException(e);
}
}
@@ -143,8 +150,8 @@ public class ScriptCommand implements ClientCommand {
} catch (ScriptException e) {
String message = e.getCause() != null ? e.getCause().getMessage() : e.getMessage();
- message = message.replace("sun.org.mozilla.javascript.internal.EcmaError: ","");
- message = message.replace("(<Unknown source>#1) in <Unknown source> at line number 1","");
+ message = message.replace("sun.org.mozilla.javascript.internal.EcmaError: ", "");
+ message = message.replace("(<Unknown source>#1) in <Unknown source> at line number 1", "");
client.getPrintWriter().println(message);
client.getPrintWriter().println(script);
@@ -162,9 +169,10 @@ public class ScriptCommand implements ClientCommand {
public void initBindings(ClientMain client) {
if (jsEngine == null) {
bindings = new StandardBindings(client.getPrintWriter(), client.getRemoteClient());
-
+
try {
- jsEngine = ScriptEngineFactory.getScriptEngine("JavaScript", new PackageFinder(Arrays.asList(getLibDir())), bindings);
+ jsEngine = ScriptEngineFactory.getScriptEngine("JavaScript", new PackageFinder(Arrays
+ .asList(getLibDir())), bindings);
jsEngine.eval("1+1");
} catch (ScriptException e) {
e.printStackTrace();
@@ -172,19 +180,20 @@ public class ScriptCommand implements ClientCommand {
e.printStackTrace();
}
}
-
+
bindings.getSubject().setValue(client.getSubject());
bindings.getPretty().getValue().setWidth(client.getConsoleWidth());
bindings.getProxyFactory().setValue(new EditableResourceClientFactory(client));
-
+
//non-standard bindings
bindings.put("configurationEditor", new ConfigurationEditor(client));
bindings.put("rhq", new Controller(client));
ScriptEngineFactory.injectStandardBindings(jsEngine, bindings, false);
-
- ScriptEngineFactory.bindIndirectionMethods(jsEngine, "configurationEditor", bindings.get("configurationEditor"));
- ScriptEngineFactory.bindIndirectionMethods(jsEngine, "rhq", bindings.get("rhq"));
+
+ ScriptEngineFactory
+ .bindIndirectionMethods(jsEngine, "configurationEditor", bindings.get("configurationEditor"));
+ ScriptEngineFactory.bindIndirectionMethods(jsEngine, "rhq", bindings.get("rhq"));
}
private void executeUtilScripts() {
@@ -253,8 +262,7 @@ public class ScriptCommand implements ClientCommand {
if (client.isInteractiveMode()) {
client.getPrintWriter().println(e.getMessage());
client.getPrintWriter().println("^");
- }
- else {
+ } else {
throw new CLIScriptException(e);
}
}
@@ -270,8 +278,8 @@ public class ScriptCommand implements ClientCommand {
}
public String getDetailedHelp() {
- return "Execute a statement or a script. The following services managers are available: " +
- RhqManagers.values();
+ return "Execute a statement or a script. The following services managers are available: "
+ + RhqManagers.values();
}
public ScriptContext getContext() {
commit 19c89919315d3a13f2894f9da829f1384e710053
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Thu Jul 28 16:20:31 2011 -0400
close streams (didn't see a coverity alert on this - I just came across it)
diff --git a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/Version.java b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/Version.java
index 89280d9..e7f63a4 100644
--- a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/Version.java
+++ b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/Version.java
@@ -184,7 +184,11 @@ public class Version {
Properties newProps = new Properties();
try {
- newProps.load(stream);
+ try {
+ newProps.load(stream);
+ } finally {
+ stream.close();
+ }
} catch (Exception e) {
throw new RuntimeException(e);
}
commit b7a146b5eae72b2545ceead0a45c79420355be7a
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Thu Jul 28 16:18:49 2011 -0400
[coverity] close stream
diff --git a/modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/Version.java b/modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/Version.java
index 84e9ec0..0150a9c 100644
--- a/modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/Version.java
+++ b/modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/Version.java
@@ -190,7 +190,11 @@ public class Version {
try {
URL jarUrl = Version.class.getProtectionDomain().getCodeSource().getLocation();
JarFile jarFile = new JarFile(new File(jarUrl.toURI()));
- manifest = jarFile.getManifest();
+ try {
+ manifest = jarFile.getManifest();
+ } finally {
+ jarFile.close();
+ }
} catch (Exception e) {
return new Properties();
}
12 years, 9 months
[rhq] Branch 'code-smell' - modules/enterprise
by mazz
modules/enterprise/comm/src/main/java/org/rhq/enterprise/communications/util/DumpBytes.java | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
New commits:
commit 2a8e27ee809f2d812b72b15fcbb5ee8a0485c653
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Thu Jul 28 16:15:31 2011 -0400
[converity] close stream
diff --git a/modules/enterprise/comm/src/main/java/org/rhq/enterprise/communications/util/DumpBytes.java b/modules/enterprise/comm/src/main/java/org/rhq/enterprise/communications/util/DumpBytes.java
index 8bb9865..4d5848f 100644
--- a/modules/enterprise/comm/src/main/java/org/rhq/enterprise/communications/util/DumpBytes.java
+++ b/modules/enterprise/comm/src/main/java/org/rhq/enterprise/communications/util/DumpBytes.java
@@ -167,9 +167,13 @@ public class DumpBytes {
int num_bytes;
try {
- fis = new FileInputStream(file);
file_contents = new byte[(int) file.length()];
- num_bytes = fis.read(file_contents);
+ fis = new FileInputStream(file);
+ try {
+ num_bytes = fis.read(file_contents);
+ } finally {
+ fis.close();
+ }
if (num_bytes != file_contents.length) {
throw new IllegalStateException(num_bytes + "!=" + file_contents.length);
12 years, 9 months
[rhq] Branch 'code-smell' - modules/enterprise
by mazz
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/SystemGWTServiceImpl.java | 14 ++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
New commits:
commit 0fac1e88882631275804d98d47c910b005f1050e
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Thu Jul 28 16:11:15 2011 -0400
[coverity] close input streams
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/SystemGWTServiceImpl.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/SystemGWTServiceImpl.java
index 052bf11..db04c59 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/SystemGWTServiceImpl.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/SystemGWTServiceImpl.java
@@ -92,7 +92,12 @@ public class SystemGWTServiceImpl extends AbstractGWTServiceImpl implements Syst
File file = agentManager.getAgentUpdateVersionFile();
Properties props = new Properties();
- props.load(new FileInputStream(file));
+ FileInputStream inStream = new FileInputStream(file);
+ try {
+ props.load(inStream);
+ } finally {
+ inStream.close();
+ }
return convertFromProperties(props);
} catch (Throwable t) {
@@ -143,7 +148,12 @@ public class SystemGWTServiceImpl extends AbstractGWTServiceImpl implements Syst
File versionFile = new File(getClientDownloadDir(), "rhq-client-version.properties");
try {
Properties p = new Properties();
- p.load(new FileInputStream(versionFile));
+ FileInputStream inStream = new FileInputStream(versionFile);
+ try {
+ p.load(inStream);
+ } finally {
+ inStream.close();
+ }
return convertFromProperties(p);
} catch (Throwable t) {
throw getExceptionToThrowToClient(t, "Unable to retrieve client version info.");
12 years, 9 months
[rhq] Branch 'code-smell' - modules/core
by mazz
modules/core/plugin-container/src/main/java/org/rhq/core/pc/content/RetrieveContentBitsRunner.java | 13 ++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
New commits:
commit 2e3d2af81ea989a9dad7d9ccc5c6e551a085d879
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Thu Jul 28 15:53:19 2011 -0400
[coverity] close input streams
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/content/RetrieveContentBitsRunner.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/content/RetrieveContentBitsRunner.java
index 3bdafda..b339190 100644
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/content/RetrieveContentBitsRunner.java
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/content/RetrieveContentBitsRunner.java
@@ -86,7 +86,12 @@ public class RetrieveContentBitsRunner implements Runnable {
InputStream is;
try {
is = contentManager.performGetPackageBits(request.getResourceId(), request.getPackageDetails());
- pkgDetails.setSHA256(new MessageDigestGenerator(MessageDigestGenerator.SHA_256).calcDigestString(is));
+ try {
+ pkgDetails.setSHA256(new MessageDigestGenerator(MessageDigestGenerator.SHA_256)
+ .calcDigestString(is));
+ } finally {
+ is.close();
+ }
} catch (Exception e) {
e.printStackTrace();
}
@@ -95,7 +100,11 @@ public class RetrieveContentBitsRunner implements Runnable {
InputStream is;
try {
is = contentManager.performGetPackageBits(request.getResourceId(), request.getPackageDetails());
- pkgDetails.setMD5((new MessageDigestGenerator(MessageDigestGenerator.MD5).calcDigestString(is)));
+ try {
+ pkgDetails.setMD5((new MessageDigestGenerator(MessageDigestGenerator.MD5).calcDigestString(is)));
+ } finally {
+ is.close();
+ }
} catch (Exception e) {
e.printStackTrace();
}
12 years, 9 months
[rhq] Branch 'code-smell' - modules/enterprise
by mazz
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/util/LookupUtil.java | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
New commits:
commit 302b7ee7c388f0db5f7cf926308034b5041de7ad
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Thu Jul 28 15:44:49 2011 -0400
[coverity] be nice and close the context. don't worry about doing it
in a try-finally - if the lookup fails, we have more important things
to worry about then not closing the context - such as we don't
have a hibernate entity manager available!
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/util/LookupUtil.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/util/LookupUtil.java
index b399741..e9ff990 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/util/LookupUtil.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/util/LookupUtil.java
@@ -266,6 +266,7 @@ public final class LookupUtil {
try {
InitialContext context = new InitialContext();
EntityManagerFactory factory = (EntityManagerFactory) context.lookup(RHQConstants.ENTITY_MANAGER_JNDI_NAME);
+ context.close();
return factory.createEntityManager();
} catch (Exception e) {
throw new RuntimeException("Failed to create an entity manager", e);
@@ -653,7 +654,8 @@ public final class LookupUtil {
localJNDIName = getLocalJNDIName(type);
return (T) lookup(localJNDIName);
} catch (NamingException e) {
- throw new RuntimeException("Failed to lookup local interface to EJB " + type + ", localJNDI=[" + localJNDIName + "]", e);
+ throw new RuntimeException("Failed to lookup local interface to EJB " + type + ", localJNDI=["
+ + localJNDIName + "]", e);
}
}
12 years, 9 months
[rhq] Branch 'code-smell' - modules/core
by mazz
modules/core/domain/src/test/java/org/rhq/core/domain/test/AbstractEJB3Test.java | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
New commits:
commit 796ac12453e260f24228add540934d9a128804bf
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Thu Jul 28 15:40:00 2011 -0400
[coverity] close the initial context
diff --git a/modules/core/domain/src/test/java/org/rhq/core/domain/test/AbstractEJB3Test.java b/modules/core/domain/src/test/java/org/rhq/core/domain/test/AbstractEJB3Test.java
index 85fb5b8..a2bdaa9 100644
--- a/modules/core/domain/src/test/java/org/rhq/core/domain/test/AbstractEJB3Test.java
+++ b/modules/core/domain/src/test/java/org/rhq/core/domain/test/AbstractEJB3Test.java
@@ -109,12 +109,20 @@ public abstract class AbstractEJB3Test extends AssertJUnit {
}
public EntityManager getEntityManager() {
+ InitialContext initialContext = null;
try {
- return ((EntityManagerFactory) getInitialContext().lookup("java:/RHQEntityManagerFactory"))
+ initialContext = getInitialContext();
+ return ((EntityManagerFactory) initialContext.lookup("java:/RHQEntityManagerFactory"))
.createEntityManager();
} catch (NamingException e) {
e.printStackTrace();
throw new RuntimeException("Failed to load entity manager", e);
+ } finally {
+ try {
+ initialContext.close();
+ } catch (Exception e) {
+ throw new RuntimeException("Failed to close the initial context - why did this happen?", e);
+ }
}
}
12 years, 9 months
[rhq] Branch 'code-smell' - modules/core
by mazz
modules/core/domain/src/test/java/org/rhq/core/domain/test/AbstractEJB3Test.java | 16 ++++++----
1 file changed, 11 insertions(+), 5 deletions(-)
New commits:
commit a07dc82e8347ce2f1e7e42f9520fb3d4d5f7f3b6
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Thu Jul 28 15:33:05 2011 -0400
[coverity] closing the initial context explicitly
diff --git a/modules/core/domain/src/test/java/org/rhq/core/domain/test/AbstractEJB3Test.java b/modules/core/domain/src/test/java/org/rhq/core/domain/test/AbstractEJB3Test.java
index 57ec318..85fb5b8 100644
--- a/modules/core/domain/src/test/java/org/rhq/core/domain/test/AbstractEJB3Test.java
+++ b/modules/core/domain/src/test/java/org/rhq/core/domain/test/AbstractEJB3Test.java
@@ -35,15 +35,13 @@ import javax.transaction.TransactionManager;
import org.testng.AssertJUnit;
import org.testng.annotations.AfterGroups;
-import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeGroups;
-import org.testng.annotations.BeforeSuite;
import org.jboss.ejb3.embedded.EJB3StandaloneBootstrap;
import org.jboss.ejb3.embedded.EJB3StandaloneDeployer;
public abstract class AbstractEJB3Test extends AssertJUnit {
-// @BeforeSuite(groups = "integration.ejb3")
+ // @BeforeSuite(groups = "integration.ejb3")
@BeforeGroups(groups = "integration.ejb3")
public static void startupEmbeddedJboss() {
System.out.println("Starting ejb3...");
@@ -84,7 +82,7 @@ public abstract class AbstractEJB3Test extends AssertJUnit {
}
}
-// @AfterSuite
+ // @AfterSuite
@AfterGroups(groups = "integration.ejb3")
public static void shutdownEmbeddedJboss() {
EJB3StandaloneBootstrap.shutdown();
@@ -93,12 +91,20 @@ public abstract class AbstractEJB3Test extends AssertJUnit {
private TransactionManager tm;
public TransactionManager getTransactionManager() {
+ InitialContext initialContext = null;
try {
- tm = (TransactionManager) getInitialContext().lookup("java:/TransactionManager");
+ initialContext = getInitialContext();
+ tm = (TransactionManager) initialContext.lookup("java:/TransactionManager");
return tm;
} catch (NamingException e) {
e.printStackTrace();
throw new RuntimeException("Failed to load transaction manager", e);
+ } finally {
+ try {
+ initialContext.close();
+ } catch (Exception e) {
+ throw new RuntimeException("Failed to close the initial context - why did this happen?", e);
+ }
}
}
12 years, 9 months
[rhq] Branch 'code-smell' - modules/core
by mazz
modules/core/client-api/src/test/java/org/rhq/core/clientapi/descriptor/PluginTransformerTest.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
New commits:
commit e0bb9de07efb271a80e98f53a4c09e75c9b1d73e
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Thu Jul 28 15:23:01 2011 -0400
[coverity] close the jar file for the test
diff --git a/modules/core/client-api/src/test/java/org/rhq/core/clientapi/descriptor/PluginTransformerTest.java b/modules/core/client-api/src/test/java/org/rhq/core/clientapi/descriptor/PluginTransformerTest.java
index 2e3374f..714d9b5 100644
--- a/modules/core/client-api/src/test/java/org/rhq/core/clientapi/descriptor/PluginTransformerTest.java
+++ b/modules/core/client-api/src/test/java/org/rhq/core/clientapi/descriptor/PluginTransformerTest.java
@@ -311,7 +311,7 @@ public class PluginTransformerTest {
JarFile jarFile = new JarFile(pluginJarFile);
Manifest manifest = jarFile.getManifest();
Attributes attributes = manifest.getMainAttributes();
-
+ jarFile.close();
return attributes.getValue(Attributes.Name.IMPLEMENTATION_VERSION);
}
12 years, 9 months
[rhq] Branch 'code-smell' - modules/core
by mazz
modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/metadata/i18n/PropertiesGenerator.java | 53 +++++-----
1 file changed, 30 insertions(+), 23 deletions(-)
New commits:
commit 59a739e6a77f05d48ede89e5dc416ea670ad478c
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Thu Jul 28 15:13:36 2011 -0400
[coverity] this isn't used anywhere, but we may revive it later. close the input stream properly.
diff --git a/modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/metadata/i18n/PropertiesGenerator.java b/modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/metadata/i18n/PropertiesGenerator.java
index 93a9c56..3c9d64f 100644
--- a/modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/metadata/i18n/PropertiesGenerator.java
+++ b/modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/metadata/i18n/PropertiesGenerator.java
@@ -1,25 +1,25 @@
- /*
- * RHQ Management Platform
- * Copyright (C) 2005-2008 Red Hat, Inc.
- * All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2, as
- * published by the Free Software Foundation, and/or the GNU Lesser
- * General Public License, version 2.1, also as published by the Free
- * Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License and the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU General Public License
- * and the GNU Lesser General Public License along with this program;
- * if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2008 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
package org.rhq.core.clientapi.agent.metadata.i18n;
import java.io.File;
@@ -34,9 +34,11 @@ import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
+
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
+
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
@@ -106,7 +108,12 @@ public class PropertiesGenerator {
if (update) {
// First load into properties we can check for existence
previousProperties = new Properties();
- previousProperties.load(new FileInputStream(propertiesFile));
+ FileInputStream is = new FileInputStream(propertiesFile);
+ try {
+ previousProperties.load(is);
+ } finally {
+ is.close();
+ }
this.contentWriter.println("\n\n# Contents added " + new Date() + "\n\n");
}
12 years, 9 months
[rhq] Branch 'code-smell' - modules/core
by mazz
modules/core/util/src/main/java/org/rhq/core/util/file/JarContentFileInfo.java | 1 +
1 file changed, 1 insertion(+)
New commits:
commit 2300051a18838bb45b6f33ca4a15ffba8f076c2a
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Thu Jul 28 15:08:43 2011 -0400
[coverity] make sure we close the jar file
diff --git a/modules/core/util/src/main/java/org/rhq/core/util/file/JarContentFileInfo.java b/modules/core/util/src/main/java/org/rhq/core/util/file/JarContentFileInfo.java
index c24fb54..529f317 100644
--- a/modules/core/util/src/main/java/org/rhq/core/util/file/JarContentFileInfo.java
+++ b/modules/core/util/src/main/java/org/rhq/core/util/file/JarContentFileInfo.java
@@ -168,6 +168,7 @@ public class JarContentFileInfo extends ContentFileInfo {
JarFile jarFile = new JarFile(file);
if (null != jarFile) {
manifest = jarFile.getManifest();
+ jarFile.close();
}
} else {
File manifestFile = new File(file, "/META-INF/MANIFEST.MF");
12 years, 9 months