modules/core/domain/src/main/java/org/rhq/core/server/EntitySerializer.java
| 29 ++
modules/core/plugin-container/src/main/java/org/rhq/core/pc/StandaloneContainer.java
| 20 +
modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/InventoryFile.java
| 23 --
modules/core/plugin-container/src/main/java/org/rhq/core/pc/plugin/PluginClassLoader.java
| 32 +-
modules/core/plugin-container/src/main/java/org/rhq/core/pc/standaloneContainer/History.java
| 23 +-
modules/core/plugindoc/src/main/java/org/rhq/core/tool/plugindoc/PluginDocGenerator.java
| 14 -
modules/core/plugindoc/src/main/java/org/rhq/core/tool/plugindoc/VelocityTemplateProcessor.java
| 14 -
modules/core/util/src/main/java/org/rhq/core/util/PropertiesFileUpdate.java
| 24 +-
modules/core/util/src/main/java/org/rhq/core/util/ZipUtil.java
| 33 ++-
modules/core/util/src/main/java/org/rhq/core/util/maven/MavenArtifactProperties.java
| 6
modules/enterprise/agentupdate/src/main/java/org/rhq/enterprise/agent/update/AgentUpdate.java
| 25 +-
modules/enterprise/binding/src/main/java/org/rhq/bindings/client/ResourceClientProxy.java
| 8
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/GwtRelativeDurationConverter.java
| 4
modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/DownloadsUIBean.java
| 15 +
modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/CreateNewPackageUIBean.java
| 97 ++++----
modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/inventory/resource/CreateNewPackageChildResourceUIBean.java
| 108 +++++-----
modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/legacy/action/resource/group/inventory/GroupForm.java
| 38 +--
modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/legacy/util/ContextUtils.java
| 6
modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/ClientMain.java
| 2
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/AgentManagerBean.java
| 34 +--
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/CoreServer.java
| 54 ++---
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/ServerPluginsBean.java
| 22 +-
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ServerPluginClassLoader.java
| 36 +--
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/perspective/PerspectiveServerPluginManager.java
| 24 +-
modules/enterprise/server/plugins/alert-operations/src/main/java/org/rhq/enterprise/server/plugins/alertOperations/PrintTokens.java
| 11 -
modules/enterprise/server/plugins/alert-snmp/src/main/java/org/rhq/enterprise/server/plugins/alertSnmp/SnmpTrapSender.java
| 54 ++---
modules/enterprise/server/plugins/rhnhosted/src/main/java/org/rhq/enterprise/server/plugins/rhnhosted/RHNHelper.java
| 8
modules/enterprise/server/plugins/rhnhosted/src/main/java/org/rhq/enterprise/server/plugins/rhnhosted/certificate/PublicKeyRing.java
| 18 +
modules/enterprise/server/plugins/yum/src/main/java/org/rhq/enterprise/server/plugins/yum/Repo.java
| 8
modules/helpers/bundleGen/src/main/java/org/rhq/helpers/bundleGen/BundleGen.java
| 39 ++-
modules/helpers/pluginGen/src/main/java/org/rhq/helpers/pluginGen/PluginGen.java
| 1
modules/integration-tests/apache-plugin-test/src/test/java/org/rhq/plugins/apache/util/ApacheDeploymentUtil.java
| 43 +--
modules/jopr/tools/jbas5-plugin-descriptor-gen/src/main/java/org/jboss/jopr/tool/jbas5/PluginDescriptorGenerator.java
| 17 -
modules/plugins/apache/src/main/java/org/rhq/plugins/apache/ModJKComponent.java
| 78 +++----
modules/plugins/apache/src/main/java/org/rhq/plugins/apache/augeas/AugeasConfigurationApache.java
| 33 +--
modules/plugins/apache/src/main/java/org/rhq/plugins/apache/augeas/mappingImpl/MappingToAugeasDirectivePerMapIndex.java
| 4
modules/plugins/apache/src/main/java/org/rhq/plugins/apache/augeas/mappingImpl/MappingToAugeasParamPerMap.java
| 4
modules/plugins/apache/src/main/java/org/rhq/plugins/apache/mapping/ApacheDirectiveRegExpression.java
| 2
modules/plugins/apache/src/main/java/org/rhq/plugins/apache/mapping/SpecificParams.java
| 6
modules/plugins/apache/src/main/java/org/rhq/plugins/apache/parser/ApacheConfigWriter.java
| 14 -
modules/plugins/apache/src/main/java/org/rhq/plugins/apache/parser/ApacheDirective.java
| 2
modules/plugins/apache/src/main/java/org/rhq/plugins/apache/util/AugeasNodeSearch.java
| 4
modules/plugins/apache/src/main/java/org/rhq/plugins/www/snmp/SNMPClient.java
| 7
modules/plugins/augeas/src/main/java/org/rhq/augeas/tree/AugeasNodeBuffer.java
| 2
modules/plugins/augeas/src/main/java/org/rhq/rhqtransform/impl/ConfigurationToAugeasSimple.java
| 10
modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/ApplicationServerContentFacetDelegate.java
| 1
modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/ApplicationServerDiscoveryComponent.java
| 14 +
modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/deploy/ManagedComponentDeployer.java
| 14 -
modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/util/JnpConfig.java
| 24 +-
modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/AbstractBaseDiscovery.java
| 13 -
modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseProcessDiscovery.java
| 11 -
modules/plugins/jboss-as/src/main/java/org/rhq/plugins/jbossas/util/FileContentDelegate.java
| 14 -
modules/plugins/jboss-as/src/main/java/org/rhq/plugins/jbossas/util/JnpConfig.java
| 24 +-
modules/plugins/jboss-cache-v3/src/test/java/org/rhq/plugins/jbosscache3/test/TestHelper.java
| 2
modules/plugins/script2/src/main/java/org/rhq/modules/plugins/script2/ScriptComponent.java
| 31 +-
modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/helper/FileContentDelegate.java
| 2
56 files changed, 684 insertions(+), 522 deletions(-)
New commits:
commit 2f32a3fa1b23531126c5b10d300e2cc4f4960702
Merge: a594d1b b31e834
Author: Robert Buck <rbuck(a)redhat.com>
Date: Thu Sep 29 14:36:13 2011 -0400
Merge branch 'master' into code-smell
* master:
BZ 738029 - partially revert the change of BZ 536496, so that plugins that still use
the deprecated (and useless) attribute can be deployed. Spit out a warning to the
console.
commit a594d1bbafdcde8f2a35ea7f169ac8360e9ff953
Author: Robert Buck <rbuck(a)redhat.com>
Date: Thu Sep 29 14:35:16 2011 -0400
revert inlined returns to non-inlined returns so folks can place a breakpoint on the
return
diff --git
a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/inventory/resource/CreateNewPackageChildResourceUIBean.java
b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/inventory/resource/CreateNewPackageChildResourceUIBean.java
index 7722508..eee311b 100644
---
a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/inventory/resource/CreateNewPackageChildResourceUIBean.java
+++
b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/inventory/resource/CreateNewPackageChildResourceUIBean.java
@@ -300,9 +300,10 @@ public class CreateNewPackageChildResourceUIBean {
deployTimeConfigurationTemplates = configDef.getDefaultTemplate();
}
- return (deployTimeConfigurationTemplates != null) ?
deployTimeConfigurationTemplates
+ Configuration deployTimeConfiguration = (deployTimeConfigurationTemplates !=
null) ? deployTimeConfigurationTemplates
.createConfiguration()
: new Configuration();
+ return deployTimeConfiguration;
}
// Accessors --------------------------------------------
@@ -331,7 +332,8 @@ public class CreateNewPackageChildResourceUIBean {
}
}
- return selectItemsList.toArray(new SelectItem[selectItemsList.size()]);
+ SelectItem[] items = selectItemsList.toArray(new
SelectItem[selectItemsList.size()]);
+ return items;
}
public CreateResourceHistory getRetryCreateItem() {
commit 5c127ed94b8f25fb37fcdca514fc389dd8e3fdfd
Author: Robert Buck <rbuck(a)redhat.com>
Date: Thu Sep 29 10:07:09 2011 -0400
revert some inlining; some folks seem to prefer non-inlined returns as a breakpoint
spot
diff --git a/modules/core/domain/src/main/java/org/rhq/core/server/EntitySerializer.java
b/modules/core/domain/src/main/java/org/rhq/core/server/EntitySerializer.java
index 88e7705..cdacd46 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/server/EntitySerializer.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/server/EntitySerializer.java
@@ -98,7 +98,8 @@ public class EntitySerializer {
Collections.sort(serializableFields, fieldComparator);
- return serializableFields.toArray(new Field[serializableFields.size()]);
+ Field[] results = serializableFields.toArray(new
Field[serializableFields.size()]);
+ return results;
}
private static List<Field> getNonEntityFieldList(Object object) {
diff --git
a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/DownloadsUIBean.java
b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/DownloadsUIBean.java
index ff402b5..e9695fb 100644
---
a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/DownloadsUIBean.java
+++
b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/DownloadsUIBean.java
@@ -57,7 +57,8 @@ public class DownloadsUIBean implements Serializable {
public List<File> getConnectorDownloadFiles() throws Exception {
File downloadDir = getConnectorDownloadsDir();
- return getFiles(downloadDir);
+ List<File> files = getFiles(downloadDir);
+ return files;
}
private File getConnectorDownloadsDir() throws Exception {
diff --git
a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/CreateNewPackageUIBean.java
b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/CreateNewPackageUIBean.java
index 8a97186..2a08598 100644
---
a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/CreateNewPackageUIBean.java
+++
b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/CreateNewPackageUIBean.java
@@ -132,7 +132,8 @@ public class CreateNewPackageUIBean {
selectedArchitectureId = getBackingPackageArchitectureId();
selectedPackageTypeId = getBackingPackageTypeId();
}
- return createNewPackage(packageName, version, selectedArchitectureId,
selectedPackageTypeId);
+ String response = createNewPackage(packageName, version, selectedArchitectureId,
selectedPackageTypeId);
+ return response;
}
public String createNewPackage(String packageName, String version, int
architectureId, int packageTypeId) {
@@ -539,4 +540,4 @@ public class CreateNewPackageUIBean {
return repoId;
}
-}
\ No newline at end of file
+}
diff --git
a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/inventory/resource/CreateNewPackageChildResourceUIBean.java
b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/inventory/resource/CreateNewPackageChildResourceUIBean.java
index fcb75b4..7722508 100644
---
a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/inventory/resource/CreateNewPackageChildResourceUIBean.java
+++
b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/inventory/resource/CreateNewPackageChildResourceUIBean.java
@@ -281,7 +281,8 @@ public class CreateNewPackageChildResourceUIBean {
resourceType = lookupResourceType();
}
ContentManagerLocal contentManager = LookupUtil.getContentManager();
- return contentManager.getResourceCreationPackageType(this.resourceType.getId());
+ PackageType packageType =
contentManager.getResourceCreationPackageType(this.resourceType.getId());
+ return packageType;
}
protected ConfigurationDefinition lookupConfigurationDefinition() {
@@ -433,4 +434,4 @@ public class CreateNewPackageChildResourceUIBean {
return items;
}
-}
\ No newline at end of file
+}
diff --git
a/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/ApplicationServerDiscoveryComponent.java
b/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/ApplicationServerDiscoveryComponent.java
index a08e977..a69f928 100644
---
a/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/ApplicationServerDiscoveryComponent.java
+++
b/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/ApplicationServerDiscoveryComponent.java
@@ -146,7 +146,8 @@ public class ApplicationServerDiscoveryComponent implements
ResourceDiscoveryCom
} catch (IOException e) {
throw new InvalidPluginConfigurationException(e);
}
- return createResourceDetails(discoveryContext, pluginConfig, processInfo,
installInfo);
+ DiscoveredResourceDetails resourceDetails =
createResourceDetails(discoveryContext, pluginConfig, processInfo, installInfo);
+ return resourceDetails;
}
@SuppressWarnings("unchecked")
diff --git
a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/AbstractBaseDiscovery.java
b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/AbstractBaseDiscovery.java
index c5bf3ff..388b614 100644
---
a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/AbstractBaseDiscovery.java
+++
b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/AbstractBaseDiscovery.java
@@ -197,7 +197,8 @@ public abstract class AbstractBaseDiscovery<T extends
ResourceComponent<?>> impl
if (hostXml==null)
throw new IllegalArgumentException("hostXml is null. You need to call
'readStandaloneOrHostXml' first.");
- return hostXml.getDocumentElement().getAttribute("name");
+ String hostName = hostXml.getDocumentElement().getAttribute("name");
+ return hostName;
}
/**
diff --git
a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseProcessDiscovery.java
b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseProcessDiscovery.java
index 3f37e34..1b5a855 100644
---
a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseProcessDiscovery.java
+++
b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseProcessDiscovery.java
@@ -74,7 +74,7 @@ public class BaseProcessDiscovery extends AbstractBaseDiscovery
implements Resou
String psName = psr.getProcessScan().getName();
String description = discoveryContext.getResourceType().getDescription();
String homeDir = getHomeDirFromCommandLine(commandLine);
- String version;
+ String version = null;
//retrieve specific boot log file. Override for Standalone as server.log is
more appropriate
String bootLogFile = getLogFileFromCommandLine(commandLine);
@@ -164,7 +164,7 @@ public class BaseProcessDiscovery extends AbstractBaseDiscovery
implements Resou
DiscoveredResourceDetails detail = new
DiscoveredResourceDetails(discoveryContext.getResourceType(), // ResourceType
serverNameFull, // key TODO distinguish per domain?
serverName, // Name
- version, // TODO get via API ?�
+ version, // TODO get via API ?
description, // Description
config, psr.getProcessInfo());
commit 51462a41002f335bbfe7cc80af8d3fa74766af78
Merge: 3132cba 566527b
Author: Robert Buck <rbuck(a)redhat.com>
Date: Thu Sep 29 09:21:26 2011 -0400
merge master to code-smell
diff --cc modules/core/util/src/main/java/org/rhq/core/util/PropertiesFileUpdate.java
index 9ac9ead,60ae7cb..2389268
--- a/modules/core/util/src/main/java/org/rhq/core/util/PropertiesFileUpdate.java
+++ b/modules/core/util/src/main/java/org/rhq/core/util/PropertiesFileUpdate.java
@@@ -186,4 -181,23 +191,23 @@@ public class PropertiesFileUpdate
return props;
}
+
+ private String trimString(String str, boolean trimStart, boolean trimEnd) {
+ int start = 0;
+ int end = str.length();
+
+ if (trimStart) {
+ while ((start < end) && (str.charAt(start) == ' ')) {
+ start++;
+ }
+ }
+
+ if (trimEnd) {
+ while ((start < end) && (str.charAt(end - 1) == ' ')) {
+ end--;
+ }
+ }
+
+ return ((start > 0) || (end < str.length())) ? str.substring(start, end) :
str;
+ }
-}
+}
diff --cc
modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseProcessDiscovery.java
index 9d4c2f2,8e73205..3f37e34
---
a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseProcessDiscovery.java
+++
b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseProcessDiscovery.java
@@@ -77,7 -73,8 +73,8 @@@ public class BaseProcessDiscovery exten
String serverName;
String psName = psr.getProcessScan().getName();
String description = discoveryContext.getResourceType().getDescription();
+ String homeDir = getHomeDirFromCommandLine(commandLine);
- String version = null;
+ String version;
//retrieve specific boot log file. Override for Standalone as server.log is
more appropriate
String bootLogFile = getLogFileFromCommandLine(commandLine);
commit 3132cbae82742a6e32adc598c81eaa574c45462b
Author: Robert Buck <rbuck(a)redhat.com>
Date: Thu Aug 11 12:30:07 2011 -0400
[BZ 726435][coverity 13064, 13106, 13115, 13231, 13232, 13283, 13346] Fix Coverity
identified RESOURCE_LEAK; close some IO streams.
diff --git a/modules/core/domain/src/main/java/org/rhq/core/server/EntitySerializer.java
b/modules/core/domain/src/main/java/org/rhq/core/server/EntitySerializer.java
index 323a15c..88e7705 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/server/EntitySerializer.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/server/EntitySerializer.java
@@ -49,7 +49,6 @@ import javax.persistence.Id;
import org.rhq.core.domain.resource.Agent;
import org.rhq.core.domain.resource.Resource;
import org.rhq.core.domain.resource.ResourceType;
-import org.rhq.core.server.ExternalizableStrategy;
import org.rhq.core.server.ExternalizableStrategy.Subsystem;
/**
@@ -99,8 +98,7 @@ public class EntitySerializer {
Collections.sort(serializableFields, fieldComparator);
- Field[] results = serializableFields.toArray(new
Field[serializableFields.size()]);
- return results;
+ return serializableFields.toArray(new Field[serializableFields.size()]);
}
private static List<Field> getNonEntityFieldList(Object object) {
@@ -252,25 +250,29 @@ public class EntitySerializer {
String tempDir = System.getProperty("java.io.tmpdir");
File tempFile = new File(tempDir, "entitySerializerTest.txt");
- ObjectOutput output = null;
+ FileOutputStream fos = new FileOutputStream(tempFile);
try {
- output = new ObjectOutputStream(new FileOutputStream(tempFile));
- writeExternalRemote(writeResource, output);
- } finally {
- if (output != null) {
+ ObjectOutput output = new ObjectOutputStream(fos);
+ try {
+ writeExternalRemote(writeResource, output);
+ } finally {
output.close();
}
+ } finally {
+ fos.close();
}
Resource readResource = new Resource();
- ObjectInput input = null;
+ FileInputStream fis = new FileInputStream(tempFile);
try {
- input = new ObjectInputStream(new FileInputStream(tempFile));
- readExternalRemote(readResource, input);
- } finally {
- if (input != null) {
- input.close();
+ ObjectInput ois = new ObjectInputStream(fis);
+ try {
+ readExternalRemote(readResource, ois);
+ } finally {
+ ois.close();
}
+ } finally {
+ fis.close();
}
// quick verification
diff --git
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/StandaloneContainer.java
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/StandaloneContainer.java
index fe4ee1c..10b1b1b 100644
---
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/StandaloneContainer.java
+++
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/StandaloneContainer.java
@@ -18,11 +18,7 @@
*/
package org.rhq.core.pc;
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.InputStreamReader;
+import java.io.*;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashMap;
@@ -93,18 +89,26 @@ public class StandaloneContainer {
if (argv.length == 0) {
br = new BufferedReader(new InputStreamReader(System.in));
isStdin = true;
+ sc.run(br);
}
else {
try {
br = new BufferedReader(new InputStreamReader(new
FileInputStream(argv[0])));
- isStdin=false;
+ try {
+ isStdin=false;
+ sc.run(br);
+ } finally {
+ try {
+ br.close();
+ } catch (IOException e) {
+ System.err.println("IOException happened: " + e +
"\n");
+ }
+ }
} catch (FileNotFoundException fnfe) {
System.err.println("File " + argv[0] + " not
found");
System.exit(1);
}
}
-
- sc.run(br);
}
/**
diff --git
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/InventoryFile.java
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/InventoryFile.java
index ea5e7fd..023a93e 100644
---
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/InventoryFile.java
+++
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/InventoryFile.java
@@ -205,22 +205,19 @@ public class InventoryFile {
*/
public void storeInventory(Resource platformResource, Map<String,
ResourceContainer> containers) throws IOException {
FileOutputStream fos = new FileOutputStream(inventoryFile);
-
try {
ObjectOutputStream oos = new ObjectOutputStream(fos);
-
- oos.writeObject(platformResource);
- oos.writeObject(containers);
-
- this.platform = platformResource;
- this.resourceContainers = containers;
- } finally {
- if (fos != null) {
- try {
- fos.close();
- } catch (Exception e) {
- }
+ try {
+ oos.writeObject(platformResource);
+ oos.writeObject(containers);
+
+ this.platform = platformResource;
+ this.resourceContainers = containers;
+ } finally {
+ oos.close();
}
+ } finally {
+ fos.close();
}
}
}
\ No newline at end of file
diff --git
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/plugin/PluginClassLoader.java
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/plugin/PluginClassLoader.java
index a9b07f2..dd72117 100644
---
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/plugin/PluginClassLoader.java
+++
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/plugin/PluginClassLoader.java
@@ -215,24 +215,26 @@ public class PluginClassLoader extends URLClassLoader {
}
throw ex;
}
-
- BufferedOutputStream outputStream = new
BufferedOutputStream(fileOutputStream);
try {
- file.deleteOnExit();
-
- // do NOT close this inputStream since it is buffering the
ZipInputStream
- // and we are going to still process that input stream later.
We close
- // this ZipInputStream down below in the outer most
try-finally block.
- BufferedInputStream inputStream = new
BufferedInputStream(zis);
-
- int count;
- byte[] b = new byte[8192];
- while ((count = inputStream.read(b)) > -1) {
- outputStream.write(b, 0, count);
+ BufferedOutputStream outputStream = new
BufferedOutputStream(fileOutputStream);
+ try {
+ file.deleteOnExit();
+
+ // do NOT close this inputStream since it is buffering
the ZipInputStream
+ // and we are going to still process that input stream
later. We close
+ // this ZipInputStream down below in the outer most
try-finally block.
+ BufferedInputStream inputStream = new
BufferedInputStream(zis);
+
+ int count;
+ byte[] b = new byte[8192];
+ while ((count = inputStream.read(b)) > -1) {
+ outputStream.write(b, 0, count);
+ }
+ } finally {
+ outputStream.close(); // this also closes the
fileOutputStream
}
} finally {
- outputStream.flush();
- outputStream.close(); // this also closes the
fileOutputStream
+ fileOutputStream.close();
}
} catch (IOException ioe) {
if (file != null) {
diff --git
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/standaloneContainer/History.java
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/standaloneContainer/History.java
index 37b5bf1..bef499b 100644
---
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/standaloneContainer/History.java
+++
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/standaloneContainer/History.java
@@ -102,17 +102,20 @@ public class History {
}
File file = new File(tokens[1]);
try {
- file.createNewFile();
- if (file.canWrite()) {
- Writer writer = new FileWriter(file);
- for (String item : history) {
- writer.write(item);
- writer.write("\n");
+ if (file.createNewFile()) {
+ if (file.canWrite()) {
+ Writer writer = new FileWriter(file);
+ try {
+ for (String item : history) {
+ writer.write(item);
+ writer.write("\n");
+ }
+ } finally {
+ writer.close();
+ }
+ } else {
+ System.err.println("Can not write to file " + file);
}
- writer.flush();
- writer.close();
- } else {
- System.err.println("Can not write to file " + file);
}
} catch (IOException ioe) {
System.err.println("Saving the history to file " + file +
" failed: " + ioe.getMessage());
diff --git a/modules/core/util/src/main/java/org/rhq/core/util/ZipUtil.java
b/modules/core/util/src/main/java/org/rhq/core/util/ZipUtil.java
index 8affe98..7c7ccfb 100644
--- a/modules/core/util/src/main/java/org/rhq/core/util/ZipUtil.java
+++ b/modules/core/util/src/main/java/org/rhq/core/util/ZipUtil.java
@@ -144,11 +144,16 @@ public abstract class ZipUtil {
File parentDirectoryFile = new File(parentDirectory);
parentDirectoryFile.mkdirs();
- BufferedOutputStream outputStream = new BufferedOutputStream(new
FileOutputStream(entryFile));
+ FileOutputStream fos = new FileOutputStream(entryFile);
try {
- StreamUtil.copy(zis, outputStream, false);
+ BufferedOutputStream outputStream = new
BufferedOutputStream(fos);
+ try {
+ StreamUtil.copy(zis, outputStream, false);
+ } finally {
+ outputStream.close();
+ }
} finally {
- outputStream.close();
+ fos.close();
}
}
}
@@ -167,18 +172,24 @@ public abstract class ZipUtil {
* @throws Exception if any errors occur during the reading or visiting
*/
public static void walkZipFile(File zipFile, ZipEntryVisitor visitor) throws
Exception {
- InputStream zipContent = new BufferedInputStream(new FileInputStream(zipFile));
+ FileInputStream fis = new FileInputStream(zipFile);
try {
- ZipInputStream zis = new ZipInputStream(zipContent);
- ZipEntry e;
- while ((e = zis.getNextEntry()) != null) {
- boolean keepGoing = visitor.visit(e, zis);
- if (!keepGoing) {
- break; // visitor told us to stop
+ InputStream zipContent = new BufferedInputStream(fis);
+ try {
+ ZipInputStream zis = new ZipInputStream(zipContent);
+
+ ZipEntry e;
+ while ((e = zis.getNextEntry()) != null) {
+ boolean keepGoing = visitor.visit(e, zis);
+ if (!keepGoing) {
+ break; // visitor told us to stop
+ }
}
+ } finally {
+ zipContent.close();
}
} finally {
- zipContent.close();
+ fis.close();
}
}
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/AgentManagerBean.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/AgentManagerBean.java
index e20bf6b..ff94188 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/AgentManagerBean.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/AgentManagerBean.java
@@ -480,24 +480,28 @@ public class AgentManagerBean implements AgentManagerLocal {
// second, get the agent version info (by peeking into the agent update
binary jar)
JarFile binaryJarFile = new JarFile(binaryFile);
- JarEntry binaryJarFileEntry =
binaryJarFile.getJarEntry("rhq-agent-update-version.properties");
- InputStream binaryJarFileEntryStream =
binaryJarFile.getInputStream(binaryJarFileEntry);
-
- // now write the server and agent version info in our internal version file
our servlet will use
- FileOutputStream versionFileOutputStream = new
FileOutputStream(versionFile);
try {
- versionFileOutputStream.write(serverVersionInfo.toString().getBytes());
- versionFileOutputStream.write(md5Property.getBytes());
- StreamUtil.copy(binaryJarFileEntryStream, versionFileOutputStream,
false);
- } finally {
- try {
- versionFileOutputStream.close();
- } catch (Exception e) {
- }
+ JarEntry binaryJarFileEntry =
binaryJarFile.getJarEntry("rhq-agent-update-version.properties");
+ InputStream binaryJarFileEntryStream =
binaryJarFile.getInputStream(binaryJarFileEntry);
+
+ // now write the server and agent version info in our internal version
file our servlet will use
+ FileOutputStream versionFileOutputStream = new
FileOutputStream(versionFile);
try {
- binaryJarFileEntryStream.close();
- } catch (Exception e) {
+
versionFileOutputStream.write(serverVersionInfo.toString().getBytes());
+ versionFileOutputStream.write(md5Property.getBytes());
+ StreamUtil.copy(binaryJarFileEntryStream, versionFileOutputStream,
false);
+ } finally {
+ try {
+ versionFileOutputStream.close();
+ } catch (Exception e) {
+ }
+ try {
+ binaryJarFileEntryStream.close();
+ } catch (Exception e) {
+ }
}
+ } finally {
+ binaryJarFile.close();
}
}
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/ServerPluginsBean.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/ServerPluginsBean.java
index a4103c4..4091720 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/ServerPluginsBean.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/ServerPluginsBean.java
@@ -646,24 +646,24 @@ public class ServerPluginsBean implements ServerPluginsLocal {
ResultSet rs = null;
FileInputStream fis = new FileInputStream(file);
-
try {
conn = this.dataSource.getConnection();
ps = conn.prepareStatement("UPDATE " + ServerPlugin.TABLE_NAME +
" SET CONTENT = ? WHERE ID = ?");
- ps.setBinaryStream(1, new BufferedInputStream(fis), (int) file.length());
- ps.setInt(2, id);
- int updateResults = ps.executeUpdate();
- if (updateResults != 1) {
- throw new Exception("Failed to update content for plugin [" +
id + "] from [" + file + "]");
+ BufferedInputStream bis = new BufferedInputStream(fis);
+ try {
+ ps.setBinaryStream(1, bis, (int) file.length());
+ ps.setInt(2, id);
+ int updateResults = ps.executeUpdate();
+ if (updateResults != 1) {
+ throw new Exception("Failed to update content for plugin ["
+ id + "] from [" + file + "]");
+ }
+ } finally {
+ bis.close();
}
} finally {
JDBCUtil.safeClose(conn, ps, rs);
-
- try {
- fis.close();
- } catch (Throwable t) {
- }
+ fis.close();
}
return;
}
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ServerPluginClassLoader.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ServerPluginClassLoader.java
index 90e2117..00b0141 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ServerPluginClassLoader.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ServerPluginClassLoader.java
@@ -144,23 +144,26 @@ public class ServerPluginClassLoader extends URLClassLoader {
throw ex;
}
- BufferedOutputStream outputStream = new
BufferedOutputStream(fileOutputStream);
try {
- file.deleteOnExit();
-
- // do NOT close this inputStream since it is buffering the
ZipInputStream
- // and we are going to still process that input stream later.
We close
- // this ZipInputStream down below in the outer most
try-finally block.
- BufferedInputStream inputStream = new
BufferedInputStream(zis);
-
- int count;
- byte[] b = new byte[8192];
- while ((count = inputStream.read(b)) > -1) {
- outputStream.write(b, 0, count);
+ BufferedOutputStream outputStream = new
BufferedOutputStream(fileOutputStream);
+ try {
+ file.deleteOnExit();
+
+ // do NOT close this inputStream since it is buffering
the ZipInputStream
+ // and we are going to still process that input stream
later. We close
+ // this ZipInputStream down below in the outer most
try-finally block.
+ BufferedInputStream inputStream = new
BufferedInputStream(zis);
+
+ int count;
+ byte[] b = new byte[8192];
+ while ((count = inputStream.read(b)) > -1) {
+ outputStream.write(b, 0, count);
+ }
+ } finally {
+ outputStream.close(); // this also closes the
fileOutputStream
}
} finally {
- outputStream.flush();
- outputStream.close(); // this also closes the
fileOutputStream
+ fileOutputStream.close();
}
} catch (IOException ioe) {
if (file != null) {
@@ -171,10 +174,7 @@ public class ServerPluginClassLoader extends URLClassLoader {
}
}
} finally {
- try {
- zis.close();
- } catch (Exception e) {
- }
+ zis.close();
}
return extractionDirectory;
commit 421022285376d56a807a62e45fb0637c76131602
Author: Robert Buck <rbuck(a)redhat.com>
Date: Thu Aug 11 09:06:56 2011 -0400
[BZ 726435][coverity] Fix Coverity identified RESOURCE_LEAK; close some IO streams.
diff --git a/modules/core/util/src/main/java/org/rhq/core/util/PropertiesFileUpdate.java
b/modules/core/util/src/main/java/org/rhq/core/util/PropertiesFileUpdate.java
index fd8dac1..9ac9ead 100644
--- a/modules/core/util/src/main/java/org/rhq/core/util/PropertiesFileUpdate.java
+++ b/modules/core/util/src/main/java/org/rhq/core/util/PropertiesFileUpdate.java
@@ -78,17 +78,22 @@ public class PropertiesFileUpdate {
// if the given property is new (doesn't exist in the file yet) just append
it and return
// if the property exists, update the value in place (ignore if the value
isn't really changing)
if (!existingProps.containsKey(key)) {
- PrintStream ps = new PrintStream(new FileOutputStream(file, true), true,
"8859_1");
- ps.println(key + "=" + value);
- ps.flush();
- ps.close();
+ FileOutputStream fos = new FileOutputStream(file, true);
+ try {
+ PrintStream ps = new PrintStream(fos, true, "8859_1");
+ try {
+ ps.println(key + "=" + value);
+ } finally {
+ ps.close();
+ }
+ } finally {
+ fos.close();
+ }
} else if (!value.equals(existingProps.getProperty(key))) {
Properties newProp = new Properties();
newProp.setProperty(key, value);
update(newProp);
}
-
- return;
}
/**
@@ -158,8 +163,6 @@ public class PropertiesFileUpdate {
fos.write(baos.toByteArray());
fos.flush();
fos.close();
-
- return;
}
/**
@@ -174,10 +177,13 @@ public class PropertiesFileUpdate {
if (file.exists()) {
FileInputStream is = new FileInputStream(file);
- props.load(is);
- is.close();
+ try {
+ props.load(is);
+ } finally {
+ is.close();
+ }
}
return props;
}
-}
\ No newline at end of file
+}
diff --git
a/modules/core/util/src/main/java/org/rhq/core/util/maven/MavenArtifactProperties.java
b/modules/core/util/src/main/java/org/rhq/core/util/maven/MavenArtifactProperties.java
index 4e749b5..5d82adc 100644
---
a/modules/core/util/src/main/java/org/rhq/core/util/maven/MavenArtifactProperties.java
+++
b/modules/core/util/src/main/java/org/rhq/core/util/maven/MavenArtifactProperties.java
@@ -133,7 +133,11 @@ public class MavenArtifactProperties {
}
Properties props = new Properties();
try {
- props.load(inputStream);
+ try {
+ props.load(inputStream);
+ } finally {
+ inputStream.close();
+ }
} catch (IOException e) {
LOG.error("Failed to load resource " + resourcePath + " into
Properties object.", e);
return null;
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 704b48d..aaca166 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
@@ -200,8 +200,11 @@ public class AgentUpdate {
System.out.println(msg);
try {
PrintWriter pw = new PrintWriter(new FileOutputStream(logFile, true));
+ try {
pw.println(msg);
- pw.close();
+ } finally {
+ pw.close();
+ }
} catch (Throwable t) {
}
}
@@ -216,8 +219,11 @@ public class AgentUpdate {
t.printStackTrace(System.out);
try {
PrintWriter pw = new PrintWriter(new FileOutputStream(logFile, true));
- t.printStackTrace(pw);
- pw.close();
+ try {
+ t.printStackTrace(pw);
+ } finally {
+ pw.close();
+ }
} catch (Throwable t1) {
}
}
@@ -232,8 +238,11 @@ public class AgentUpdate {
System.out.println(msg);
try {
PrintWriter pw = new PrintWriter(new FileOutputStream(logFileArgument,
true));
- pw.println(msg);
- pw.close();
+ try {
+ pw.println(msg);
+ } finally {
+ pw.close();
+ }
} catch (Throwable t) {
}
}
@@ -266,7 +275,11 @@ public class AgentUpdate {
byte[] bytes = getJarFileContent(RHQ_AGENT_UPDATE_VERSION_PROPERTIES);
InputStream propertiesStream = new ByteArrayInputStream(bytes);
Properties versionProps = new Properties();
- versionProps.load(propertiesStream);
+ try {
+ versionProps.load(propertiesStream);
+ } finally {
+ propertiesStream.close();
+ }
return versionProps;
}
diff --git
a/modules/enterprise/binding/src/main/java/org/rhq/bindings/client/ResourceClientProxy.java
b/modules/enterprise/binding/src/main/java/org/rhq/bindings/client/ResourceClientProxy.java
index b850605..928468b 100644
---
a/modules/enterprise/binding/src/main/java/org/rhq/bindings/client/ResourceClientProxy.java
+++
b/modules/enterprise/binding/src/main/java/org/rhq/bindings/client/ResourceClientProxy.java
@@ -564,9 +564,11 @@ public class ResourceClientProxy {
remoteClient.getSubject(), resourceClientProxy.resourceId,
installedPackage.getId());
FileOutputStream fos = new FileOutputStream(file);
- fos.write(data);
- fos.close();
-
+ try {
+ fos.write(data);
+ } finally {
+ fos.close();
+ }
}
//
------------------------------------------------------------------------------------------------------
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/CoreServer.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/CoreServer.java
index 2d766aa..decf99e 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/CoreServer.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/CoreServer.java
@@ -133,30 +133,35 @@ public class CoreServer extends ServiceMBeanSupport implements
CoreServerMBean {
public ProductInfo getProductInfo() {
ClassLoader classLoader = this.getClass().getClassLoader();
InputStream inputStream =
classLoader.getResourceAsStream(PRODUCT_INFO_PROPERTIES_RESOURCE_PATH);
- if (inputStream == null) {
+ if (inputStream != null) {
+ Properties props = new Properties();
+ try {
+ try {
+ props.load(inputStream);
+ } finally {
+ inputStream.close();
+ }
+ } catch (IOException e) {
+ throw new IllegalStateException("Failed to load product info
properties from class loader resource ["
+ + PRODUCT_INFO_PROPERTIES_RESOURCE_PATH + "].");
+ }
+ ProductInfo productInfo = new ProductInfo();
+ // TODO: Using reflection below might be nicer.
+ productInfo.setBuildNumber(props.getProperty("buildNumber"));
+ productInfo.setFullName(props.getProperty("fullName"));
+ productInfo.setHelpDocRoot(props.getProperty("helpDocRoot"));
+ productInfo.setName(props.getProperty("name"));
+ productInfo.setSalesEmail(props.getProperty("salesEmail"));
+ productInfo.setShortName(props.getProperty("shortName"));
+ productInfo.setSupportEmail(props.getProperty("supportEmail"));
+ productInfo.setUrlDomain(props.getProperty("urlDomain"));
+ productInfo.setUrl(props.getProperty("url"));
+ productInfo.setVersion(props.getProperty("version"));
+ return productInfo;
+ } else {
throw new IllegalStateException("Failed to find class loader resource
["
+ PRODUCT_INFO_PROPERTIES_RESOURCE_PATH + "].");
}
- Properties props = new Properties();
- try {
- props.load(inputStream);
- } catch (IOException e) {
- throw new IllegalStateException("Failed to load product info properties
from class loader resource ["
- + PRODUCT_INFO_PROPERTIES_RESOURCE_PATH + "].");
- }
- ProductInfo productInfo = new ProductInfo();
- // TODO: Using reflection below might be nicer.
- productInfo.setBuildNumber(props.getProperty("buildNumber"));
- productInfo.setFullName(props.getProperty("fullName"));
- productInfo.setHelpDocRoot(props.getProperty("helpDocRoot"));
- productInfo.setName(props.getProperty("name"));
- productInfo.setSalesEmail(props.getProperty("salesEmail"));
- productInfo.setShortName(props.getProperty("shortName"));
- productInfo.setSupportEmail(props.getProperty("supportEmail"));
- productInfo.setUrlDomain(props.getProperty("urlDomain"));
- productInfo.setUrl(props.getProperty("url"));
- productInfo.setVersion(props.getProperty("version"));
- return productInfo;
}
private MBeanServer getMBeanServer() {
@@ -168,8 +173,11 @@ public class CoreServer extends ServiceMBeanSupport implements
CoreServerMBean {
ClassLoader classLoader = this.getClass().getClassLoader();
try {
InputStream stream = classLoader.getResourceAsStream(VERSION_FILE);
- buildProps.load(stream);
- stream.close();
+ try {
+ buildProps.load(stream);
+ } finally {
+ stream.close();
+ }
} catch (Exception e) {
log.fatal("Failed to load [" + VERSION_FILE + "] via class
loader [" + classLoader + "]");
}
diff --git
a/modules/enterprise/server/plugins/alert-operations/src/main/java/org/rhq/enterprise/server/plugins/alertOperations/PrintTokens.java
b/modules/enterprise/server/plugins/alert-operations/src/main/java/org/rhq/enterprise/server/plugins/alertOperations/PrintTokens.java
index a51f2fb..e7bbcd9 100644
---
a/modules/enterprise/server/plugins/alert-operations/src/main/java/org/rhq/enterprise/server/plugins/alertOperations/PrintTokens.java
+++
b/modules/enterprise/server/plugins/alert-operations/src/main/java/org/rhq/enterprise/server/plugins/alertOperations/PrintTokens.java
@@ -49,11 +49,12 @@ public class PrintTokens {
out = new BufferedOutputStream(new FileOutputStream(file));
}
- String text = createTokenDescription();
-
- out.write(text.getBytes());
- out.flush();
- out.close();
+ try {
+ String text = createTokenDescription();
+ out.write(text.getBytes());
+ } finally {
+ out.close();
+ }
}
/**
diff --git
a/modules/enterprise/server/plugins/alert-snmp/src/main/java/org/rhq/enterprise/server/plugins/alertSnmp/SnmpTrapSender.java
b/modules/enterprise/server/plugins/alert-snmp/src/main/java/org/rhq/enterprise/server/plugins/alertSnmp/SnmpTrapSender.java
index 4389779..ba4bf84 100644
---
a/modules/enterprise/server/plugins/alert-snmp/src/main/java/org/rhq/enterprise/server/plugins/alertSnmp/SnmpTrapSender.java
+++
b/modules/enterprise/server/plugins/alert-snmp/src/main/java/org/rhq/enterprise/server/plugins/alertSnmp/SnmpTrapSender.java
@@ -197,35 +197,37 @@ public class SnmpTrapSender implements PDUFactory {
public PDU send() throws IOException {
Snmp snmp = createSnmpSession();
- this.target = createTarget();
- target.setVersion(version);
- target.setAddress(address);
- target.setRetries(retries);
- target.setTimeout(timeout);
- snmp.listen();
-
- PDU request = createPDU(target);
- if (request.getType() == PDU.GETBULK) {
- request.setMaxRepetitions(maxRepetitions);
- request.setNonRepeaters(nonRepeaters);
- }
+ try {
+ this.target = createTarget();
+ target.setVersion(version);
+ target.setAddress(address);
+ target.setRetries(retries);
+ target.setTimeout(timeout);
+ snmp.listen();
+
+ PDU request = createPDU(target);
+ if (request.getType() == PDU.GETBULK) {
+ request.setMaxRepetitions(maxRepetitions);
+ request.setNonRepeaters(nonRepeaters);
+ }
- for (Object vb : vbs) {
- request.add((VariableBinding) vb);
- }
+ for (Object vb : vbs) {
+ request.add((VariableBinding) vb);
+ }
- PDU response = null;
- ResponseEvent responseEvent;
- long startTime = System.currentTimeMillis();
- responseEvent = snmp.send(request, target);
- if (responseEvent != null) {
- response = responseEvent.getResponse();
- if (log.isDebugEnabled())
- log.debug("Received response after " +
(System.currentTimeMillis() - startTime) + " millis");
+ PDU response = null;
+ ResponseEvent responseEvent;
+ long startTime = System.currentTimeMillis();
+ responseEvent = snmp.send(request, target);
+ if (responseEvent != null) {
+ response = responseEvent.getResponse();
+ if (log.isDebugEnabled())
+ log.debug("Received response after " +
(System.currentTimeMillis() - startTime) + " millis");
+ }
+ return response;
+ } finally {
+ snmp.close();
}
-
- snmp.close();
- return response;
}
private void getVariableBindings(String args) {
diff --git
a/modules/enterprise/server/plugins/rhnhosted/src/main/java/org/rhq/enterprise/server/plugins/rhnhosted/RHNHelper.java
b/modules/enterprise/server/plugins/rhnhosted/src/main/java/org/rhq/enterprise/server/plugins/rhnhosted/RHNHelper.java
index ac02551..62e3afd 100644
---
a/modules/enterprise/server/plugins/rhnhosted/src/main/java/org/rhq/enterprise/server/plugins/rhnhosted/RHNHelper.java
+++
b/modules/enterprise/server/plugins/rhnhosted/src/main/java/org/rhq/enterprise/server/plugins/rhnhosted/RHNHelper.java
@@ -470,9 +470,11 @@ public class RHNHelper {
ByteArrayOutputStream zipped = new ByteArrayOutputStream();
GZIPOutputStream gzip = new GZIPOutputStream(zipped);
- gzip.write(input);
- gzip.flush();
- gzip.close();
+ try {
+ gzip.write(input);
+ } finally {
+ gzip.close();
+ }
return zipped.toByteArray();
}
diff --git
a/modules/enterprise/server/plugins/rhnhosted/src/main/java/org/rhq/enterprise/server/plugins/rhnhosted/certificate/PublicKeyRing.java
b/modules/enterprise/server/plugins/rhnhosted/src/main/java/org/rhq/enterprise/server/plugins/rhnhosted/certificate/PublicKeyRing.java
index a29f272..ba45aee 100644
---
a/modules/enterprise/server/plugins/rhnhosted/src/main/java/org/rhq/enterprise/server/plugins/rhnhosted/certificate/PublicKeyRing.java
+++
b/modules/enterprise/server/plugins/rhnhosted/src/main/java/org/rhq/enterprise/server/plugins/rhnhosted/certificate/PublicKeyRing.java
@@ -89,7 +89,7 @@ public class PublicKeyRing {
throws SignatureException {
PGPSignature sig = decodeSignature(asciiSig);
PGPPublicKey key;
- boolean result = false;
+ boolean result;
try {
key = keyRing.getPublicKey(sig.getKeyID());
sig.initVerify(key, RhnSecurityProvider.NAME);
@@ -119,12 +119,20 @@ public class PublicKeyRing {
* @return the signature
*/
private static PGPSignature decodeSignature(String asciiSig) {
- PGPSignature result = null;
+ PGPSignature result;
ByteArrayInputStream bais = new ByteArrayInputStream(asciiSig.getBytes());
try {
- InputStream in = PGPUtil.getDecoderStream(new ArmoredInputStream(bais));
- result = ((PGPSignatureList) new PGPObjectFactory(in).nextObject()).get(0);
- in.close();
+ ArmoredInputStream ais = new ArmoredInputStream(bais);
+ try {
+ InputStream in = PGPUtil.getDecoderStream(ais);
+ try {
+ result = ((PGPSignatureList) new
PGPObjectFactory(in).nextObject()).get(0);
+ } finally {
+ in.close();
+ }
+ } finally {
+ ais.close();
+ }
}
catch (IOException e) {
// This is so unlikely that we convert it to a runtime exception
diff --git
a/modules/enterprise/server/plugins/yum/src/main/java/org/rhq/enterprise/server/plugins/yum/Repo.java
b/modules/enterprise/server/plugins/yum/src/main/java/org/rhq/enterprise/server/plugins/yum/Repo.java
index 318a031..616dad4 100644
---
a/modules/enterprise/server/plugins/yum/src/main/java/org/rhq/enterprise/server/plugins/yum/Repo.java
+++
b/modules/enterprise/server/plugins/yum/src/main/java/org/rhq/enterprise/server/plugins/yum/Repo.java
@@ -251,9 +251,11 @@ public class Repo {
XMLOutputter printer = new XMLOutputter();
ByteArrayOutputStream zipped = new ByteArrayOutputStream();
GZIPOutputStream gzip = new GZIPOutputStream(zipped);
- printer.output(p, gzip);
- gzip.flush();
- gzip.close();
+ try {
+ printer.output(p, gzip);
+ } finally {
+ gzip.close();
+ }
return zipped.toByteArray();
}
}
\ No newline at end of file
diff --git
a/modules/helpers/bundleGen/src/main/java/org/rhq/helpers/bundleGen/BundleGen.java
b/modules/helpers/bundleGen/src/main/java/org/rhq/helpers/bundleGen/BundleGen.java
index bdda353..6160643 100644
--- a/modules/helpers/bundleGen/src/main/java/org/rhq/helpers/bundleGen/BundleGen.java
+++ b/modules/helpers/bundleGen/src/main/java/org/rhq/helpers/bundleGen/BundleGen.java
@@ -156,11 +156,13 @@ public class BundleGen {
Template templ = config.getTemplate(template + ".ftl");
Writer out = new BufferedWriter(new FileWriter(new File(directory,
fileName)));
- Map<String, Props> root = new HashMap<String, Props>();
- root.put("props", props);
- templ.process(root, out);
- out.flush();
- out.close();
+ try {
+ Map<String, Props> root = new HashMap<String, Props>();
+ root.put("props", props);
+ templ.process(root, out);
+ } finally {
+ out.close();
+ }
} catch (IOException ioe) {
ioe.printStackTrace();
} catch (TemplateException te) {
diff --git
a/modules/helpers/pluginGen/src/main/java/org/rhq/helpers/pluginGen/PluginGen.java
b/modules/helpers/pluginGen/src/main/java/org/rhq/helpers/pluginGen/PluginGen.java
index 3b76d52..223a57f 100644
--- a/modules/helpers/pluginGen/src/main/java/org/rhq/helpers/pluginGen/PluginGen.java
+++ b/modules/helpers/pluginGen/src/main/java/org/rhq/helpers/pluginGen/PluginGen.java
@@ -363,7 +363,6 @@ public class PluginGen {
templ.process(root, out);
}
finally {
- out.flush();
out.close();
}
} catch (IOException ioe) {
diff --git
a/modules/integration-tests/apache-plugin-test/src/test/java/org/rhq/plugins/apache/util/ApacheDeploymentUtil.java
b/modules/integration-tests/apache-plugin-test/src/test/java/org/rhq/plugins/apache/util/ApacheDeploymentUtil.java
index 6183694..bc80898 100644
---
a/modules/integration-tests/apache-plugin-test/src/test/java/org/rhq/plugins/apache/util/ApacheDeploymentUtil.java
+++
b/modules/integration-tests/apache-plugin-test/src/test/java/org/rhq/plugins/apache/util/ApacheDeploymentUtil.java
@@ -350,47 +350,30 @@ public class ApacheDeploymentUtil {
Map<String, String> replacements = config.getTokenReplacements();
for (File file : configFiles) {
- Reader rdr = null;
- FileWriter wrt = null;
-
try {
- rdr = new TokenReplacingReader(new FileReader(file), replacements);
-
File tmp = File.createTempFile("apache-deployment-util",
null);
- wrt = new FileWriter(tmp);
-
- int cnt = -1;
-
- while ((cnt = rdr.read(buffer)) != -1) {
- wrt.write(buffer, 0, cnt);
+ FileWriter wrt = new FileWriter(tmp);
+ try {
+ Reader rdr = new TokenReplacingReader(new FileReader(file),
replacements);
+ try {
+ int cnt = -1;
+ while ((cnt = rdr.read(buffer)) != -1) {
+ wrt.write(buffer, 0, cnt);
+ }
+ } finally {
+ rdr.close();
+ }
+ } finally {
+ wrt.close();
}
- rdr.close();
- wrt.close();
-
//now overwrite the contents of the original file with the new one.
//we don't just move the new file to the location of the original
one
//here to preserve the file permissions and file mode on the original.
FileUtil.copyFile(tmp, file);
} catch (IOException e) {
LOG.error("Error while replacing the tokens in file '" +
file + "'.", e);
-
- if (rdr != null) {
- try {
- rdr.close();
- } catch (IOException ioe) {
-
- }
- }
-
- if (wrt != null) {
- try {
- wrt.close();
- } catch (IOException ioe) {
-
- }
- }
}
}
}
diff --git
a/modules/jopr/tools/jbas5-plugin-descriptor-gen/src/main/java/org/jboss/jopr/tool/jbas5/PluginDescriptorGenerator.java
b/modules/jopr/tools/jbas5-plugin-descriptor-gen/src/main/java/org/jboss/jopr/tool/jbas5/PluginDescriptorGenerator.java
index 49e6089..5019fea 100644
---
a/modules/jopr/tools/jbas5-plugin-descriptor-gen/src/main/java/org/jboss/jopr/tool/jbas5/PluginDescriptorGenerator.java
+++
b/modules/jopr/tools/jbas5-plugin-descriptor-gen/src/main/java/org/jboss/jopr/tool/jbas5/PluginDescriptorGenerator.java
@@ -371,12 +371,15 @@ public class PluginDescriptorGenerator
{
LOG.info("Writing plugin descriptor to [" + file + "]...");
OutputStream outputStream = new BufferedOutputStream(new
FileOutputStream(file));
- JAXBContext jaxbContext = JAXBContext.newInstance(DescriptorPackages.PC_PLUGIN);
- Marshaller marshaller = jaxbContext.createMarshaller();
- marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
- marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
- marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", new
RhqNamespacePrefixMapper());
- marshaller.marshal(pluginDescriptor, outputStream);
- outputStream.close();
+ try {
+ JAXBContext jaxbContext =
JAXBContext.newInstance(DescriptorPackages.PC_PLUGIN);
+ Marshaller marshaller = jaxbContext.createMarshaller();
+ marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
+ marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
+ marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper",
new RhqNamespacePrefixMapper());
+ marshaller.marshal(pluginDescriptor, outputStream);
+ } finally {
+ outputStream.close();
+ }
}
}
diff --git a/modules/plugins/apache/src/main/java/org/rhq/plugins/www/snmp/SNMPClient.java
b/modules/plugins/apache/src/main/java/org/rhq/plugins/www/snmp/SNMPClient.java
index 974f8ef..0b04d77 100644
--- a/modules/plugins/apache/src/main/java/org/rhq/plugins/www/snmp/SNMPClient.java
+++ b/modules/plugins/apache/src/main/java/org/rhq/plugins/www/snmp/SNMPClient.java
@@ -95,10 +95,13 @@ public class SNMPClient {
}
Properties props = new Properties();
try {
- props.load(stream);
+ try {
+ props.load(stream);
+ } finally {
+ stream.close();
+ }
} catch (Exception e) {
throw new IllegalStateException("Failed to parse oids.properties file
from plugin classloader.", e);
-
}
Enumeration<?> propNames = props.propertyNames();
diff --git
a/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/ApplicationServerContentFacetDelegate.java
b/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/ApplicationServerContentFacetDelegate.java
index 6166076..05ca8e7 100644
---
a/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/ApplicationServerContentFacetDelegate.java
+++
b/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/ApplicationServerContentFacetDelegate.java
@@ -185,7 +185,6 @@ public class ApplicationServerContentFacetDelegate extends
AbstractJBossASConten
// Request the bits from the server
try {
contentServices.downloadPackageBits(contentContext, key, bufferedOutput,
true);
- bufferedOutput.close();
// Verify the file was created correctly
File downloadedFile = new File(destinationFileLocation);
diff --git
a/modules/plugins/script2/src/main/java/org/rhq/modules/plugins/script2/ScriptComponent.java
b/modules/plugins/script2/src/main/java/org/rhq/modules/plugins/script2/ScriptComponent.java
index 1df7f29..4a22007 100644
---
a/modules/plugins/script2/src/main/java/org/rhq/modules/plugins/script2/ScriptComponent.java
+++
b/modules/plugins/script2/src/main/java/org/rhq/modules/plugins/script2/ScriptComponent.java
@@ -97,17 +97,28 @@ public class ScriptComponent implements ResourceComponent,
MeasurementFacet, Ope
if (!scriptFile.exists())
throw new InvalidPluginConfigurationException("Script does not exist at
" + scriptFile.getAbsolutePath());
- Reader reader;
try {
- reader = new BufferedReader(new FileReader(scriptFile));
- StringWriter writer = new StringWriter();
- int tmp;
- while ((tmp=reader.read())!=-1)
- writer.write(tmp);
-
- reader.close();
- theScript = writer.toString();
- writer.close();
+ FileReader fr = new FileReader(scriptFile);
+ try {
+ Reader reader = new BufferedReader(fr);
+ try {
+ StringWriter writer = new StringWriter();
+ try {
+ int tmp;
+ while ((tmp=reader.read())!=-1) {
+ writer.write(tmp);
+ }
+ reader.close();
+ theScript = writer.toString();
+ } finally {
+ writer.close();
+ }
+ } finally {
+ reader.close();
+ }
+ } finally {
+ fr.close();
+ }
engine.eval(theScript);
}
commit b47ed240bbd1a0bce77649fc77007383f25ca35e
Author: Robert Buck <rbuck(a)redhat.com>
Date: Wed Aug 10 10:07:08 2011 -0400
[BZ 726435] Fixed several bitwise-or uses on booleans, switching to logical-or.
diff --git
a/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/augeas/mappingImpl/MappingToAugeasDirectivePerMapIndex.java
b/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/augeas/mappingImpl/MappingToAugeasDirectivePerMapIndex.java
index f372363..f7a510e 100644
---
a/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/augeas/mappingImpl/MappingToAugeasDirectivePerMapIndex.java
+++
b/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/augeas/mappingImpl/MappingToAugeasDirectivePerMapIndex.java
@@ -182,7 +182,7 @@ public class MappingToAugeasDirectivePerMapIndex extends
ConfigurationToAugeasAp
PropertyMap propMap = (PropertyMap)prop;
PropertySimple propSim =
((PropertySimple)propMap.get("_index"));
int value;
- if (propSim ==null | propSim.getIntegerValue() == null)
+ if (propSim ==null || propSim.getIntegerValue() == null)
value = 0;
else
value = propSim.getIntegerValue().intValue();
diff --git
a/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/augeas/mappingImpl/MappingToAugeasParamPerMap.java
b/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/augeas/mappingImpl/MappingToAugeasParamPerMap.java
index 9da0cb0..f181481 100644
---
a/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/augeas/mappingImpl/MappingToAugeasParamPerMap.java
+++
b/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/augeas/mappingImpl/MappingToAugeasParamPerMap.java
@@ -133,7 +133,7 @@ public class MappingToAugeasParamPerMap extends
ConfigurationToAugeasApacheBase{
PropertyMap propMap = (PropertyMap)prop;
PropertySimple propSim =
((PropertySimple)propMap.get("_index"));
int value;
- if (propSim ==null | propSim.getIntegerValue() == null)
+ if (propSim ==null || propSim.getIntegerValue() == null)
value = 0;
else
value = propSim.getIntegerValue().intValue();
diff --git
a/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/mapping/ApacheDirectiveRegExpression.java
b/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/mapping/ApacheDirectiveRegExpression.java
index fa7d196..404fb5d 100644
---
a/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/mapping/ApacheDirectiveRegExpression.java
+++
b/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/mapping/ApacheDirectiveRegExpression.java
@@ -183,7 +183,7 @@ public class ApacheDirectiveRegExpression {
return nodeParams;
}
- if (name.equals("Allow") | name.equals("Deny")){
+ if (name.equals("Allow") || name.equals("Deny")){
nodeParams.add("from");
}
//each regex is applied as long as it matches something
diff --git
a/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/mapping/SpecificParams.java
b/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/mapping/SpecificParams.java
index 2c13f87..e600dce 100644
---
a/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/mapping/SpecificParams.java
+++
b/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/mapping/SpecificParams.java
@@ -55,7 +55,7 @@ public class SpecificParams {
if (name.equals("Listen")){
int i;
StringBuilder val = new StringBuilder(value);
- while (val.charAt(0) == ' ' | val.charAt(0) == '\t')
+ while (val.charAt(0) == ' ' || val.charAt(0) == '\t')
val.deleteCharAt(0);
String [] str = val.toString().split("[ \t]+");
diff --git
a/modules/plugins/augeas/src/main/java/org/rhq/rhqtransform/impl/ConfigurationToAugeasSimple.java
b/modules/plugins/augeas/src/main/java/org/rhq/rhqtransform/impl/ConfigurationToAugeasSimple.java
index 26a10a5..de43610 100644
---
a/modules/plugins/augeas/src/main/java/org/rhq/rhqtransform/impl/ConfigurationToAugeasSimple.java
+++
b/modules/plugins/augeas/src/main/java/org/rhq/rhqtransform/impl/ConfigurationToAugeasSimple.java
@@ -94,8 +94,8 @@ public class ConfigurationToAugeasSimple implements
ConfigurationToAugeas {
List<AugeasNode> nodes = tree.matchRelative(mapNode,
propDefMap.getName());
AugeasNode node;
- int i = 0;
- if (nodes.isEmpty() | nodes.size() < seq) {
+ int i;
+ if (nodes.isEmpty() || nodes.size() < seq) {
node = tree.createNode(mapNode, propDefMap.getName(), null, seq);
nodes.add(node);
i = ((seq == 0) ? 0 : seq - 1);
@@ -130,9 +130,9 @@ public class ConfigurationToAugeasSimple implements
ConfigurationToAugeas {
}
List<AugeasNode> nodes = tree.matchRelative(listNode, propDef.getName());
- AugeasNode node = null;
+ AugeasNode node;
- if (nodes.isEmpty() | nodes.size() < seq) {
+ if (nodes.isEmpty() || nodes.size() < seq) {
node = tree.createNode(listNode, propDef.getName(), null, seq);
nodes.add(node);
} else
@@ -150,7 +150,7 @@ public class ConfigurationToAugeasSimple implements
ConfigurationToAugeas {
throws AugeasRhqException {
PropertySimple simpleProp = null;
- AugeasNode node = null;
+ AugeasNode node;
if (prop instanceof PropertyList) {
PropertyList lst = (PropertyList) prop;
List<Property> props = lst.getList();
commit dc3c6f68af412eb7826e71ae62f43cc3c1d66a06
Author: Robert Buck <rbuck(a)redhat.com>
Date: Wed Aug 10 09:58:31 2011 -0400
[BZ 726435][coverity 13546 12979 12996] Fix Coverity identified FORWARD_NULL. Also,
fixed several bitwise-and uses on booleans, switching to logical-and.
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/configuration/ConfigurationEditor.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/configuration/ConfigurationEditor.java
index 3e1364b..b17d67a 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/configuration/ConfigurationEditor.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/configuration/ConfigurationEditor.java
@@ -586,7 +586,6 @@ public class ConfigurationEditor extends LocatableVLayout {
property, odd, fields);
odd = !odd;
}
- return;
}
public void addItemsForPropertyRecursively(String locatorId, PropertyDefinition
propertyDefinition,
@@ -1064,13 +1063,18 @@ public class ConfigurationEditor extends LocatableVLayout {
}
private PropertyMapListGridRecord[] buildSummaryRecords(PropertyList propertyList,
List<PropertyDefinition> definitions) {
- PropertyMapListGridRecord[] records = new PropertyMapListGridRecord[propertyList
== null ? 0 : propertyList.getList().size()];
- List<Property> list = propertyList.getList();
- for (int index = 0, listSize = list.size(); index < listSize; index++) {
- Property row = list.get(index);
- PropertyMap rowMap = (PropertyMap) row;
- PropertyMapListGridRecord record = new PropertyMapListGridRecord(rowMap,
index, definitions);
- records[index] = record;
+ PropertyMapListGridRecord[] records;
+ if (propertyList == null) {
+ records = new PropertyMapListGridRecord[0];
+ } else {
+ records = new PropertyMapListGridRecord[propertyList.getList().size()];
+ List<Property> list = propertyList.getList();
+ for (int index = 0, listSize = list.size(); index < listSize; index++) {
+ Property row = list.get(index);
+ PropertyMap rowMap = (PropertyMap) row;
+ PropertyMapListGridRecord record = new PropertyMapListGridRecord(rowMap,
index, definitions);
+ records[index] = record;
+ }
}
return records;
}
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/PortletFactory.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/PortletFactory.java
index 7b23c0a..0c14cb6 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/PortletFactory.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/PortletFactory.java
@@ -298,7 +298,7 @@ public class PortletFactory {
public static PortletViewFactory getRegisteredPortletFactory(String key) {
PortletViewFactory portletFactory = null;
- if ((key != null) & (!key.trim().isEmpty())) {
+ if ((key != null) && (!key.trim().isEmpty())) {
portletFactory = registeredPortletFactoryMap.get(key);
}
return portletFactory;
@@ -306,7 +306,7 @@ public class PortletFactory {
public static PortletViewFactory getRegisteredGroupPortletFactory(String key) {
PortletViewFactory portletFactory = null;
- if ((key != null) & (!key.trim().isEmpty())) {
+ if ((key != null) && (!key.trim().isEmpty())) {
portletFactory = registeredGroupPortletFactoryMap.get(key);
}
return portletFactory;
@@ -314,7 +314,7 @@ public class PortletFactory {
public static PortletViewFactory getRegisteredResourcePortletFactory(String key) {
PortletViewFactory portletFactory = null;
- if ((key != null) & (!key.trim().isEmpty())) {
+ if ((key != null) && (!key.trim().isEmpty())) {
portletFactory = registeredResourcePortletFactoryMap.get(key);
}
return portletFactory;
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/GwtRelativeDurationConverter.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/GwtRelativeDurationConverter.java
index 803df4c..0959d9b 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/GwtRelativeDurationConverter.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/GwtRelativeDurationConverter.java
@@ -37,10 +37,10 @@ public class GwtRelativeDurationConverter {
int dayOfYearEvent = Integer.parseInt(dayFormatter.format(new
Date(eventMillis)));
String result = null;
//add additional check to fix when dayOfYear and dayOfYearToday is same but month
apart.
- if ((dayOfYearEvent == dayOfYearToday) & ((now - eventMillis) <
MILLIS_IN_DAY)) {
+ if ((dayOfYearEvent == dayOfYearToday) && ((now - eventMillis) <
MILLIS_IN_DAY)) {
// <time>
result = formatter.format(new Date(eventMillis));
- } else if ((dayOfYearEvent == dayOfYearToday - 1) & ((now - eventMillis) <
MILLIS_IN_DAY * 28)) {
+ } else if ((dayOfYearEvent == dayOfYearToday - 1) && ((now - eventMillis)
< MILLIS_IN_DAY * 28)) {
// "yesterday" <time>
result = MSG.common_label_yesterday() + ", " + formatter.format(new
Date(eventMillis));
} else {
diff --git
a/modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/ClientMain.java
b/modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/ClientMain.java
index 1f6f007..b3968e6 100755
---
a/modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/ClientMain.java
+++
b/modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/ClientMain.java
@@ -219,7 +219,7 @@ public class ClientMain {
* @return flag indicating status of realtime check.
*/
public boolean loggedIn() {
- return subject != null && remoteClient != null &
remoteClient.isLoggedIn();
+ return subject != null && remoteClient != null &&
remoteClient.isLoggedIn();
}
/**
diff --git
a/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/augeas/mappingImpl/MappingToAugeasDirectivePerMapIndex.java
b/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/augeas/mappingImpl/MappingToAugeasDirectivePerMapIndex.java
index b6a3b35..f372363 100644
---
a/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/augeas/mappingImpl/MappingToAugeasDirectivePerMapIndex.java
+++
b/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/augeas/mappingImpl/MappingToAugeasDirectivePerMapIndex.java
@@ -191,7 +191,7 @@ public class MappingToAugeasDirectivePerMapIndex extends
ConfigurationToAugeasAp
map.add(propMap);
count = count + 1;
}
- if (value > min & value<next){
+ if (value > min && value<next){
next = value;
}
}
diff --git
a/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/augeas/mappingImpl/MappingToAugeasParamPerMap.java
b/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/augeas/mappingImpl/MappingToAugeasParamPerMap.java
index a274099..9da0cb0 100644
---
a/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/augeas/mappingImpl/MappingToAugeasParamPerMap.java
+++
b/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/augeas/mappingImpl/MappingToAugeasParamPerMap.java
@@ -142,7 +142,7 @@ public class MappingToAugeasParamPerMap extends
ConfigurationToAugeasApacheBase{
tempList.add(propMap);
count = count + 1;
}
- if (value > min & value<next){
+ if (value > min && value<next){
next = value;
}
}
diff --git
a/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/mapping/SpecificParams.java
b/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/mapping/SpecificParams.java
index 9d9dc33..2c13f87 100644
---
a/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/mapping/SpecificParams.java
+++
b/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/mapping/SpecificParams.java
@@ -27,7 +27,7 @@ public class SpecificParams {
Pattern pattern = Pattern.compile("[ \t]*(Add|Remove|Set)[
\t]*([a-zA-Z]+)");
int startIndex = 0;
boolean updated = true;
- while (updated & startIndex < value.length()){
+ while (updated && startIndex < value.length()){
updated = false;
Matcher m = pattern.matcher(value);
while (m.find(startIndex)) {
@@ -96,7 +96,7 @@ public class SpecificParams {
Pattern pattern = Pattern.compile("[ \t]*([+-]?)([a-zA-Z]+)");
int startIndex = 0;
boolean updated = true;
- while (updated & startIndex < value.length()){
+ while (updated && startIndex < value.length()){
updated = false;
Matcher m = pattern.matcher(value);
while (m.find(startIndex)) {
diff --git
a/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/parser/ApacheDirective.java
b/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/parser/ApacheDirective.java
index ae2f025..d02e447 100644
---
a/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/parser/ApacheDirective.java
+++
b/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/parser/ApacheDirective.java
@@ -41,7 +41,7 @@ public class ApacheDirective implements Cloneable {
}else{
int startIndex = 0;
boolean updated = true;
- while (updated & startIndex < directive.length()){
+ while (updated && startIndex < directive.length()){
updated = false;
Matcher m = DIRECTIVE_PATTERN.matcher(directive);
while (m.find(startIndex)) {
diff --git
a/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/util/AugeasNodeSearch.java
b/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/util/AugeasNodeSearch.java
index 6c3a362..077d263 100644
---
a/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/util/AugeasNodeSearch.java
+++
b/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/util/AugeasNodeSearch.java
@@ -44,7 +44,7 @@ public class AugeasNodeSearch {
boolean match = true;
int i =0;
- while (match & i<nodeParams.size() & tempNode!=parentNode){
+ while (match && i<nodeParams.size() &&
tempNode!=parentNode){
List<AugeasNode> childNodes =
tempNode.getChildByLabel("param");
if (childNodes.size()>0){
if (!nodeParams.get(i).equals(childNodes.get(0).getValue()))
@@ -135,7 +135,7 @@ public class AugeasNodeSearch {
public static String getNodeKey(AugeasNode node,AugeasNode parentNode){
AugeasNode pNode = node;
StringBuilder str = new StringBuilder();
- while (pNode!=null & !pNode.equals(parentNode))
+ while (pNode!=null && !pNode.equals(parentNode))
{
str.append(getNodeKeyFromParent(pNode));
pNode = pNode.getParentNode();
diff --git
a/modules/plugins/augeas/src/main/java/org/rhq/augeas/tree/AugeasNodeBuffer.java
b/modules/plugins/augeas/src/main/java/org/rhq/augeas/tree/AugeasNodeBuffer.java
index fd66390..9ba9e09 100644
--- a/modules/plugins/augeas/src/main/java/org/rhq/augeas/tree/AugeasNodeBuffer.java
+++ b/modules/plugins/augeas/src/main/java/org/rhq/augeas/tree/AugeasNodeBuffer.java
@@ -89,7 +89,7 @@ public class AugeasNodeBuffer {
for (String key : buffer.keySet()) {
int index = key.indexOf(parentNode.getFullPath());
- if ((index == 0) & (key.length() > parentNode.getFullPath().length()))
{
+ if ((index == 0) && (key.length() >
parentNode.getFullPath().length())) {
String localPath = key.substring(parentNode.getFullPath().length());
int endOfLabel = localPath.indexOf(File.separatorChar);
String label;
diff --git
a/modules/plugins/jboss-cache-v3/src/test/java/org/rhq/plugins/jbosscache3/test/TestHelper.java
b/modules/plugins/jboss-cache-v3/src/test/java/org/rhq/plugins/jbosscache3/test/TestHelper.java
index 7600a2e..16c453e 100644
---
a/modules/plugins/jboss-cache-v3/src/test/java/org/rhq/plugins/jbosscache3/test/TestHelper.java
+++
b/modules/plugins/jboss-cache-v3/src/test/java/org/rhq/plugins/jbosscache3/test/TestHelper.java
@@ -65,7 +65,7 @@ public class TestHelper {
public static boolean compareValues(String value, String type, Object obj) {
- if (value == null & obj == null)
+ if (value == null && obj == null)
return true;
if (type.equals("int")) {
commit f286cfe6f1b4f87516942545c6dc8d8031b12f9e
Author: Robert Buck <rbuck(a)redhat.com>
Date: Wed Aug 10 08:23:20 2011 -0400
[BZ 726435][coverity 13171] Fix Coverity identified REVERSE_INULL. Fix unnecessary
boxing of '0' to Integer object returns.
diff --git
a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/legacy/action/resource/group/inventory/GroupForm.java
b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/legacy/action/resource/group/inventory/GroupForm.java
index c222819..ffd9607 100644
---
a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/legacy/action/resource/group/inventory/GroupForm.java
+++
b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/legacy/action/resource/group/inventory/GroupForm.java
@@ -59,10 +59,10 @@ public class GroupForm extends BaseValidatorForm {
*/
public Integer getCompatibleCount() {
if ((platformTypes == null) || (serverTypes == null) || (serviceTypes == null))
{
- return new Integer(0);
+ return 0;
}
- return new Integer(platformTypes.size() + serverTypes.size() +
serviceTypes.size());
+ return platformTypes.size() + serverTypes.size() + serviceTypes.size();
}
/**
@@ -70,10 +70,10 @@ public class GroupForm extends BaseValidatorForm {
*/
public Integer getClusterCount() {
if (serviceTypes == null) {
- return new Integer(0);
+ return 0;
}
- return new Integer(serviceTypes.size());
+ return serviceTypes.size();
}
/**
@@ -92,10 +92,10 @@ public class GroupForm extends BaseValidatorForm {
*/
public Integer getPlatformTypeCount() {
if (platformTypes == null) {
- return new Integer(0);
+ return 0;
}
- return new Integer(platformTypes.size());
+ return platformTypes.size();
}
/**
@@ -114,10 +114,10 @@ public class GroupForm extends BaseValidatorForm {
*/
public Integer getServerTypeCount() {
if (serverTypes == null) {
- return new Integer(0);
+ return 0;
}
- return new Integer(serverTypes.size());
+ return serverTypes.size();
}
/**
@@ -136,10 +136,10 @@ public class GroupForm extends BaseValidatorForm {
*/
public Integer getServiceTypeCount() {
if (serviceTypes == null) {
- return new Integer(0);
+ return 0;
}
- return new Integer(serviceTypes.size());
+ return serviceTypes.size();
}
/**
@@ -170,17 +170,16 @@ public class GroupForm extends BaseValidatorForm {
}
private List<Map<String, Object>>
getOptionListItemsWithDashes(List<ResourceType> types) {
- Map<String, Integer> typeNameCounts = new HashMap<String,
Integer>();
- for (ResourceType type : types) {
- if (typeNameCounts.containsKey(type.getName()) == false) {
- typeNameCounts.put(type.getName(), 1);
- } else {
- typeNameCounts.put(type.getName(), typeNameCounts.get(type.getName()) +
1);
- }
- }
-
List<Map<String, Object>> items = new ArrayList<Map<String,
Object>>();
if (types != null) {
+ Map<String, Integer> typeNameCounts = new HashMap<String,
Integer>();
+ for (ResourceType type : types) {
+ if (!typeNameCounts.containsKey(type.getName())) {
+ typeNameCounts.put(type.getName(), 1);
+ } else {
+ typeNameCounts.put(type.getName(), typeNameCounts.get(type.getName())
+ 1);
+ }
+ }
for (ResourceType type : types) {
// GroupTypeForm needs this data format - a map with "value"
and "label" keys
Map<String, Object> map = new HashMap<String, Object>(2);
@@ -190,7 +189,6 @@ public class GroupForm extends BaseValidatorForm {
items.add(map);
}
}
-
return items;
}
commit 1eea642da40862bc5f0e9839542836cf7f5e8d8f
Author: Robert Buck <rbuck(a)redhat.com>
Date: Wed Aug 10 07:32:28 2011 -0400
[BZ 726435][coverity
13231,13284,13288,13343,13344,13361,13417,13424,13504,13521,13527,13542,14054] Fix
Coverity identified RESOURCE_LEAK; close some IO streams.
diff --git
a/modules/core/plugindoc/src/main/java/org/rhq/core/tool/plugindoc/PluginDocGenerator.java
b/modules/core/plugindoc/src/main/java/org/rhq/core/tool/plugindoc/PluginDocGenerator.java
index ee2681d..be7607b 100644
---
a/modules/core/plugindoc/src/main/java/org/rhq/core/tool/plugindoc/PluginDocGenerator.java
+++
b/modules/core/plugindoc/src/main/java/org/rhq/core/tool/plugindoc/PluginDocGenerator.java
@@ -67,17 +67,17 @@ public class PluginDocGenerator {
throw new IllegalArgumentException("Argument to loadProperties must not
be null");
}
- InputStream fileInputStream;
+ Properties props = new Properties();
try {
File f = new File(propertiesFileName);
- fileInputStream = new FileInputStream(f);
+ InputStream fileInputStream = new FileInputStream(f);
+ try {
+ props.load(fileInputStream);
+ } finally {
+ fileInputStream.close();
+ }
} catch (FileNotFoundException fnfe) {
throw new IllegalArgumentException(propertiesFileName + " file does not
exist");
- }
-
- Properties props = new Properties();
- try {
- props.load(fileInputStream);
} catch (IOException ioe) {
throw new IllegalStateException("Error loading properties from " +
propertiesFileName + ": "
+ ioe.getMessage());
diff --git
a/modules/core/plugindoc/src/main/java/org/rhq/core/tool/plugindoc/VelocityTemplateProcessor.java
b/modules/core/plugindoc/src/main/java/org/rhq/core/tool/plugindoc/VelocityTemplateProcessor.java
index 70b595f..fdc2af7 100644
---
a/modules/core/plugindoc/src/main/java/org/rhq/core/tool/plugindoc/VelocityTemplateProcessor.java
+++
b/modules/core/plugindoc/src/main/java/org/rhq/core/tool/plugindoc/VelocityTemplateProcessor.java
@@ -74,11 +74,15 @@ public class VelocityTemplateProcessor {
public void processTemplate(File outputFile) {
try {
- OutputStream outputStream = new FileOutputStream(outputFile);
- Writer writer = new BufferedWriter(new OutputStreamWriter(outputStream));
- this.template.merge(this.context, writer);
- writer.close();
- outputStream.close();
+ Writer writer = null;
+ try {
+ writer = new BufferedWriter(new OutputStreamWriter(new
FileOutputStream(outputFile)));
+ this.template.merge(this.context, writer);
+ } finally {
+ if (writer != null) {
+ writer.close();
+ }
+ }
} catch (Exception e) {
throw new RuntimeException(e);
}
diff --git
a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/DownloadsUIBean.java
b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/DownloadsUIBean.java
index bad2170..ff402b5 100644
---
a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/DownloadsUIBean.java
+++
b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/DownloadsUIBean.java
@@ -42,10 +42,14 @@ public class DownloadsUIBean implements Serializable {
File file = LookupUtil.getAgentManager().getAgentUpdateVersionFile();
Properties props = new Properties();
- props.load(new FileInputStream(file));
+ FileInputStream fis = new FileInputStream(file);
+ try {
+ props.load(fis);
+ } finally {
+ fis.close();
+ }
return props;
-
} catch (Exception e) {
throw new RuntimeException("Agent download information not
available", e);
}
@@ -53,8 +57,7 @@ public class DownloadsUIBean implements Serializable {
public List<File> getConnectorDownloadFiles() throws Exception {
File downloadDir = getConnectorDownloadsDir();
- List<File> files = getFiles(downloadDir);
- return files;
+ return getFiles(downloadDir);
}
private File getConnectorDownloadsDir() throws Exception {
@@ -79,7 +82,12 @@ public class DownloadsUIBean implements Serializable {
File versionFile = new File(getClientDownloadDir(),
"rhq-client-version.properties");
try {
Properties p = new Properties();
- p.load(new FileInputStream(versionFile));
+ FileInputStream fis = new FileInputStream(versionFile);
+ try {
+ p.load(fis);
+ } finally {
+ fis.close();
+ }
return p;
} catch (Exception e) {
throw new RuntimeException("Unable to retrieve client version
info", e);
diff --git
a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/CreateNewPackageUIBean.java
b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/CreateNewPackageUIBean.java
index 1e067be..8a97186 100644
---
a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/CreateNewPackageUIBean.java
+++
b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/CreateNewPackageUIBean.java
@@ -132,8 +132,7 @@ public class CreateNewPackageUIBean {
selectedArchitectureId = getBackingPackageArchitectureId();
selectedPackageTypeId = getBackingPackageTypeId();
}
- String response = createNewPackage(packageName, version, selectedArchitectureId,
selectedPackageTypeId);
- return response;
+ return createNewPackage(packageName, version, selectedArchitectureId,
selectedPackageTypeId);
}
public String createNewPackage(String packageName, String version, int
architectureId, int packageTypeId) {
@@ -201,12 +200,56 @@ public class CreateNewPackageUIBean {
}
try {
- // Grab a stream for the file being uploaded
- InputStream packageStream;
-
+ PackageVersion packageVersion = null;
try {
log.debug("Streaming new package bits from uploaded file: " +
fileItem.getFile());
- packageStream = new FileInputStream(fileItem.getFile());
+
+ // Grab a stream for the file being uploaded
+ InputStream packageStream = new FileInputStream(fileItem.getFile());
+ try {
+ // Ask the bean to create the package
+
+ /* Currently, this is just used in the workflow for deploying a new
package. This will probably get
+ refactored in the future for a general way of adding packages to
the repo as its own operation. For
+ now, don't worry about that. The rest of this will be written
assuming it's part of the deploy
+ workflow and we'll deal with the refactoring later.
+ jdobies, Feb 27, 2008
+ */
+ try {
+ ContentManagerLocal contentManager =
LookupUtil.getContentManager();
+
+ //store information about uploaded file for packageDetails as
most of it is already available
+ Map<String, String> packageUploadDetails = new
HashMap<String, String>();
+ packageUploadDetails.put(ContentManagerLocal.UPLOAD_FILE_SIZE,
String.valueOf(fileItem.getFileSize()));
+
packageUploadDetails.put(ContentManagerLocal.UPLOAD_FILE_INSTALL_DATE,
String.valueOf(System
+ .currentTimeMillis()));
+ packageUploadDetails.put(ContentManagerLocal.UPLOAD_OWNER,
subject.getName());
+ packageUploadDetails.put(ContentManagerLocal.UPLOAD_FILE_NAME,
fileItem.getFileName());
+
+ try {//Easier to implement here than in server side bean.
Shouldn't affect performance too much.
+ packageUploadDetails.put(ContentManagerLocal.UPLOAD_MD5, new
MessageDigestGenerator(
+
MessageDigestGenerator.MD5).calcDigestString(fileItem.getFile()));
+ packageUploadDetails.put(ContentManagerLocal.UPLOAD_SHA256,
new MessageDigestGenerator(
+
MessageDigestGenerator.SHA_256).calcDigestString(fileItem.getFile()));
+ } catch (IOException e1) {
+ log.warn("Error calculating file digest(s)", e1);
+ }
+
+ Integer iRepoId = usingARepo ? Integer.parseInt(repoId) : null;
+ packageVersion =
contentManager.getUploadedPackageVersion(subject, packageName, packageTypeId,
+ version, architectureId, packageStream, packageUploadDetails,
iRepoId);
+
+ } catch (NoResultException nre) {
+ //eat the exception. Some of the queries return no results if no
package yet exists which is fine.
+ } catch (Exception e) {
+ String errorMessages = ThrowableUtil.getAllMessages(e);
+ FacesContextUtility.addMessage(FacesMessage.SEVERITY_ERROR,
"Failed to create package [" + packageName
+ + "] in repository. Cause: " + errorMessages);
+ return "failure";
+ }
+ } finally {
+ packageStream.close();
+ }
} catch (IOException e) {
String errorMessages = ThrowableUtil.getAllMessages(e);
FacesContextUtility.addMessage(FacesMessage.SEVERITY_ERROR,
@@ -214,47 +257,6 @@ public class CreateNewPackageUIBean {
return "failure";
}
- // Ask the bean to create the package
-
- /* Currently, this is just used in the workflow for deploying a new package.
This will probably get
- refactored in the future for a general way of adding packages to the repo
as its own operation. For
- now, don't worry about that. The rest of this will be written assuming
it's part of the deploy
- workflow and we'll deal with the refactoring later.
- jdobies, Feb 27, 2008
- */
- PackageVersion packageVersion = null;
- try {
- ContentManagerLocal contentManager = LookupUtil.getContentManager();
-
- //store information about uploaded file for packageDetails as most of it
is already available
- Map<String, String> packageUploadDetails = new HashMap<String,
String>();
- packageUploadDetails.put(ContentManagerLocal.UPLOAD_FILE_SIZE,
String.valueOf(fileItem.getFileSize()));
- packageUploadDetails.put(ContentManagerLocal.UPLOAD_FILE_INSTALL_DATE,
String.valueOf(System
- .currentTimeMillis()));
- packageUploadDetails.put(ContentManagerLocal.UPLOAD_OWNER,
subject.getName());
- packageUploadDetails.put(ContentManagerLocal.UPLOAD_FILE_NAME,
fileItem.getFileName());
-
- try {//Easier to implement here than in server side bean. Shouldn't
affect performance too much.
- packageUploadDetails.put(ContentManagerLocal.UPLOAD_MD5, new
MessageDigestGenerator(
-
MessageDigestGenerator.MD5).calcDigestString(fileItem.getFile()));
- packageUploadDetails.put(ContentManagerLocal.UPLOAD_SHA256, new
MessageDigestGenerator(
-
MessageDigestGenerator.SHA_256).calcDigestString(fileItem.getFile()));
- } catch (IOException e1) {
- log.warn("Error calculating file digest(s)", e1);
- }
-
- Integer iRepoId = usingARepo ? Integer.parseInt(repoId) : null;
- packageVersion = contentManager.getUploadedPackageVersion(subject,
packageName, packageTypeId,
- version, architectureId, packageStream, packageUploadDetails,
iRepoId);
-
- } catch (NoResultException nre) {
- //eat the exception. Some of the queries return no results if no package
yet exists which is fine.
- } catch (Exception e) {
- String errorMessages = ThrowableUtil.getAllMessages(e);
- FacesContextUtility.addMessage(FacesMessage.SEVERITY_ERROR, "Failed
to create package [" + packageName
- + "] in repository. Cause: " + errorMessages);
- return "failure";
- }
int[] packageVersionList = new int[] { packageVersion.getId() };
@@ -321,7 +323,7 @@ public class CreateNewPackageUIBean {
private SelectItem[] getPackageTypes(boolean includeResourceTypeResolution) {
Resource resource = EnterpriseFacesContextUtility.getResourceIfExists();
- List<PackageType> packageTypes = null;
+ List<PackageType> packageTypes;
ContentUIManagerLocal contentUIManager = LookupUtil.getContentUIManager();
if (resource != null) {
packageTypes =
contentUIManager.getPackageTypes(resource.getResourceType().getId());
diff --git
a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/inventory/resource/CreateNewPackageChildResourceUIBean.java
b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/inventory/resource/CreateNewPackageChildResourceUIBean.java
index 3f1a3cc..fcb75b4 100644
---
a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/inventory/resource/CreateNewPackageChildResourceUIBean.java
+++
b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/inventory/resource/CreateNewPackageChildResourceUIBean.java
@@ -154,62 +154,64 @@ public class CreateNewPackageChildResourceUIBean {
}
try {
- InputStream packageContentStream;
try {
log.debug("Streaming new package bits from uploaded file: " +
fileItem.getFile());
- packageContentStream = new FileInputStream(fileItem.getFile());
- } catch (IOException e) {
- String errorMessages = ThrowableUtil.getAllMessages(e);
- FacesContextUtility.addMessage(FacesMessage.SEVERITY_ERROR,
- "Failed to retrieve the input stream. Cause: " +
errorMessages);
- return OUTCOME_SUCCESS_OR_FAILURE;
- }
-
- if (isSupportsArchitecture()) {
- // pull in architecture selection
- selectedArchitectureId = getSelectedArchitectureId();
- }
-
- // Collect data for create call
- Resource parentResource = EnterpriseFacesContextUtility.getResource();
- Configuration deployTimeConfiguration = getConfiguration();
- String packageName = fileItem.getFileName();
-
- // some browsers (IE in particular) passes an absolute filename, we just want
the name of the file, no paths
- if (packageName != null) {
- packageName = packageName.replace('\\', '/');
- if (packageName.length() > 2 && packageName.charAt(1) ==
':') {
- packageName = packageName.substring(2);
- }
- packageName = new File(packageName).getName();
- }
-
- try {
- ResourceFactoryManagerLocal resourceFactoryManager =
LookupUtil.getResourceFactoryManager();
-
- // RHQ-666 - Changed to not request the resource name from the user;
simply pass null
- // JON 2.0 RC3 - use timestamp versioning; pass null for version
- // resourceFactoryManager.createResource(user,
parentResource.getId(), getResourceTypeId(), null,
- // pluginConfiguration, packageName, null,
selectedArchitectureId, deployTimeConfiguration,
- // packageContentStream);
- if (packageUploadDetails != null) {
- resourceFactoryManager.createResource(user, parentResource.getId(),
getResourceTypeId(), null,
- pluginConfiguration, packageName, getVersion(),
selectedArchitectureId,
- deployTimeConfiguration, packageContentStream,
packageUploadDetails);
- } else {
- resourceFactoryManager.createResource(user, parentResource.getId(),
getResourceTypeId(), null,
- pluginConfiguration, packageName, null, selectedArchitectureId,
deployTimeConfiguration,
- packageContentStream);
-
+ InputStream packageContentStream = new
FileInputStream(fileItem.getFile());
+ try {
+ if (isSupportsArchitecture()) {
+ // pull in architecture selection
+ selectedArchitectureId = getSelectedArchitectureId();
+ }
+
+ // Collect data for create call
+ Resource parentResource =
EnterpriseFacesContextUtility.getResource();
+ Configuration deployTimeConfiguration = getConfiguration();
+ String packageName = fileItem.getFileName();
+
+ // some browsers (IE in particular) passes an absolute filename, we
just want the name of the file, no paths
+ if (packageName != null) {
+ packageName = packageName.replace('\\', '/');
+ if (packageName.length() > 2 && packageName.charAt(1)
== ':') {
+ packageName = packageName.substring(2);
+ }
+ packageName = new File(packageName).getName();
+ }
+
+ try {
+ ResourceFactoryManagerLocal resourceFactoryManager =
LookupUtil.getResourceFactoryManager();
+
+ // RHQ-666 - Changed to not request the resource name from the
user; simply pass null
+ // JON 2.0 RC3 - use timestamp versioning; pass null for version
+ // resourceFactoryManager.createResource(user,
parentResource.getId(), getResourceTypeId(), null,
+ // pluginConfiguration, packageName, null,
selectedArchitectureId, deployTimeConfiguration,
+ // packageContentStream);
+ if (packageUploadDetails != null) {
+ resourceFactoryManager.createResource(user,
parentResource.getId(), getResourceTypeId(), null,
+ pluginConfiguration, packageName, getVersion(),
selectedArchitectureId,
+ deployTimeConfiguration, packageContentStream,
packageUploadDetails);
+ } else {
+ resourceFactoryManager.createResource(user,
parentResource.getId(), getResourceTypeId(), null,
+ pluginConfiguration, packageName, null,
selectedArchitectureId, deployTimeConfiguration,
+ packageContentStream);
+
+ }
+
+ } catch (NoResultException nre) {
+ //eat the exception. Some of the queries return no results if no
package yet exists which is fine.
+ } catch (Exception e) {
+ String errorMessages = ThrowableUtil.getAllMessages(e);
+ FacesContextUtility.addMessage(FacesMessage.SEVERITY_ERROR,
+ "Failed to send create resource request to agent. Cause:
" + errorMessages);
+ log.error("Failed to create new child Resource of type
[" + getResourceType() + "].", e);
+ return OUTCOME_SUCCESS_OR_FAILURE;
+ }
+ } finally {
+ packageContentStream.close();
}
-
- } catch (NoResultException nre) {
- //eat the exception. Some of the queries return no results if no package
yet exists which is fine.
- } catch (Exception e) {
+ } catch (IOException e) {
String errorMessages = ThrowableUtil.getAllMessages(e);
FacesContextUtility.addMessage(FacesMessage.SEVERITY_ERROR,
- "Failed to send create resource request to agent. Cause: "
+ errorMessages);
- log.error("Failed to create new child Resource of type [" +
getResourceType() + "].", e);
+ "Failed to retrieve the input stream. Cause: " +
errorMessages);
return OUTCOME_SUCCESS_OR_FAILURE;
}
@@ -279,8 +281,7 @@ public class CreateNewPackageChildResourceUIBean {
resourceType = lookupResourceType();
}
ContentManagerLocal contentManager = LookupUtil.getContentManager();
- PackageType packageType =
contentManager.getResourceCreationPackageType(this.resourceType.getId());
- return packageType;
+ return contentManager.getResourceCreationPackageType(this.resourceType.getId());
}
protected ConfigurationDefinition lookupConfigurationDefinition() {
@@ -297,11 +298,10 @@ public class CreateNewPackageChildResourceUIBean {
if (configDef != null) {
deployTimeConfigurationTemplates = configDef.getDefaultTemplate();
}
- Configuration deployTimeConfiguration = (deployTimeConfigurationTemplates !=
null) ? deployTimeConfigurationTemplates
+
+ return (deployTimeConfigurationTemplates != null) ?
deployTimeConfigurationTemplates
.createConfiguration()
: new Configuration();
-
- return deployTimeConfiguration;
}
// Accessors --------------------------------------------
@@ -330,8 +330,7 @@ public class CreateNewPackageChildResourceUIBean {
}
}
- SelectItem[] items = selectItemsList.toArray(new
SelectItem[selectItemsList.size()]);
- return items;
+ return selectItemsList.toArray(new SelectItem[selectItemsList.size()]);
}
public CreateResourceHistory getRetryCreateItem() {
diff --git
a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/legacy/util/ContextUtils.java
b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/legacy/util/ContextUtils.java
index 994bf64..3363463 100644
---
a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/legacy/util/ContextUtils.java
+++
b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/legacy/util/ContextUtils.java
@@ -243,7 +243,11 @@ public class ContextUtils {
filename = context.getRealPath(filename);
FileOutputStream out = new FileOutputStream(filename);
- props.store(out, null);
+ try {
+ props.store(out, null);
+ } finally {
+ out.close();
+ }
}
public static boolean usingLDAPAuthentication(ServletContext context) throws
Exception {
diff --git
a/modules/helpers/bundleGen/src/main/java/org/rhq/helpers/bundleGen/BundleGen.java
b/modules/helpers/bundleGen/src/main/java/org/rhq/helpers/bundleGen/BundleGen.java
index 289b36f..bdda353 100644
--- a/modules/helpers/bundleGen/src/main/java/org/rhq/helpers/bundleGen/BundleGen.java
+++ b/modules/helpers/bundleGen/src/main/java/org/rhq/helpers/bundleGen/BundleGen.java
@@ -22,7 +22,6 @@ import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
-import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
@@ -91,13 +90,14 @@ public class BundleGen {
try {
File outFile = new File(genPath,"generatedBundle.zip");
- FileOutputStream fos = new FileOutputStream(outFile);
- ZipOutputStream zos = new ZipOutputStream(fos);
-
- copyToOutputStream(zos,genPath,"deploy.xml");
- copyToOutputStream(zos,props.getContentDir(),props.getBundleFile());
- zos.flush();
- zos.close();
+ ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(outFile));
+ try {
+ copyToOutputStream(zos,genPath,"deploy.xml");
+ copyToOutputStream(zos,props.getContentDir(),props.getBundleFile());
+ } finally {
+ // by definition this automatically flushes!
+ zos.close();
+ }
File targetFile = new File(bundleTargetDirectory + "/" +
"generatedBundle.zip");
boolean success = outFile.renameTo(targetFile);
@@ -125,10 +125,13 @@ public class BundleGen {
ZipEntry entry = new ZipEntry(fileName);
zos.putNextEntry(entry);
FileInputStream fis = new FileInputStream(new File(filedir , fileName));
- StreamUtil.copy(fis,zos,false);
- zos.flush();
- log.debug("Added ["+ fileName + "]");
- fis.close();
+ try {
+ StreamUtil.copy(fis,zos,false);
+ zos.flush();
+ log.debug("Added ["+ fileName + "]");
+ } finally {
+ fis.close();
+ }
}
/**
diff --git
a/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/parser/ApacheConfigWriter.java
b/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/parser/ApacheConfigWriter.java
index 34d5a3e..6365be6 100644
---
a/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/parser/ApacheConfigWriter.java
+++
b/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/parser/ApacheConfigWriter.java
@@ -47,16 +47,20 @@ public class ApacheConfigWriter {
}
public void saveFile(String file,ApacheDirective dir) throws Exception{
-
File fl = new File(file);
- if (!fl.exists())
+ if (!fl.exists()) {
fl.createNewFile();
+ }
OutputStream str = new FileOutputStream(fl);
- for (ApacheDirective d : dir.getChildDirectives()){
- if (dir.getFile().equals(file)){
- writeToFile(str,dir,file);
+ try {
+ for (ApacheDirective d : dir.getChildDirectives()){
+ if (dir.getFile().equals(file)){
+ writeToFile(str,dir,file);
+ }
}
+ } finally {
+ str.close();
}
}
diff --git
a/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/util/JnpConfig.java
b/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/util/JnpConfig.java
index c2c8f10..9e30732 100644
---
a/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/util/JnpConfig.java
+++
b/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/util/JnpConfig.java
@@ -488,16 +488,20 @@ public class JnpConfig {
+ "jboss-system.jar");
if (systemJar.exists()) {
JarFile j = new JarFile(systemJar);
- JarEntry entry = j.getJarEntry("dtd/" + dtdName);
- if (entry == null) {
- entry = j.getJarEntry("org/jboss/metadata/" +
dtdName);
- }
-
- if (entry != null) {
- if (log.isDebugEnabled())
- log.debug("Found DTD locally: " +
entry.getName());
-
- return new InputSource(j.getInputStream(entry));
+ try {
+ JarEntry entry = j.getJarEntry("dtd/" + dtdName);
+ if (entry == null) {
+ entry = j.getJarEntry("org/jboss/metadata/" +
dtdName);
+ }
+
+ if (entry != null) {
+ if (log.isDebugEnabled())
+ log.debug("Found DTD locally: " +
entry.getName());
+
+ return new InputSource(j.getInputStream(entry));
+ }
+ } finally {
+ j.close();
}
}
}
diff --git
a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/AbstractBaseDiscovery.java
b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/AbstractBaseDiscovery.java
index 79a4fab..f9f902e 100644
---
a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/AbstractBaseDiscovery.java
+++
b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/AbstractBaseDiscovery.java
@@ -61,8 +61,11 @@ public abstract class AbstractBaseDiscovery<T extends
ResourceComponent> impleme
try {
DocumentBuilder builder = factory.newDocumentBuilder();
InputStream is = new FileInputStream(hostXmlFile);
- hostXml = builder.parse(is);
- is.close();
+ try {
+ hostXml = builder.parse(is);
+ } finally {
+ is.close();
+ }
} catch (Exception e) {
e.printStackTrace(); // TODO: Customise this generated block
}
@@ -127,8 +130,7 @@ public abstract class AbstractBaseDiscovery<T extends
ResourceComponent> impleme
hp.port = port;
String nIf = mgmtInterface.getAttribute("interface");
- String hostName = getInterface(nIf);
- hp.host = hostName;
+ hp.host = getInterface(nIf);
return hp;
}
}
@@ -174,8 +176,7 @@ public abstract class AbstractBaseDiscovery<T extends
ResourceComponent> impleme
if (nodeName.equals("any-ipv4-address"))
return "0.0.0.0";
- String x = ((Element)
nl.item(j)).getAttribute("value");
- return x;
+ return ((Element) nl.item(j)).getAttribute("value");
// TODO check for <any> and so on
}
@@ -195,8 +196,7 @@ public abstract class AbstractBaseDiscovery<T extends
ResourceComponent> impleme
if (hostXml==null)
throw new IllegalArgumentException("hostXml is null. You need to call
'readStandaloneOrHostXml' first.");
- String hostName = hostXml.getDocumentElement().getAttribute("name");
- return hostName;
+ return hostXml.getDocumentElement().getAttribute("name");
}
/**
diff --git
a/modules/plugins/jboss-as/src/main/java/org/rhq/plugins/jbossas/util/JnpConfig.java
b/modules/plugins/jboss-as/src/main/java/org/rhq/plugins/jbossas/util/JnpConfig.java
index 38c9f0c..4441bee 100644
--- a/modules/plugins/jboss-as/src/main/java/org/rhq/plugins/jbossas/util/JnpConfig.java
+++ b/modules/plugins/jboss-as/src/main/java/org/rhq/plugins/jbossas/util/JnpConfig.java
@@ -489,16 +489,20 @@ public class JnpConfig {
+ "jboss-system.jar");
if (systemJar.exists()) {
JarFile j = new JarFile(systemJar);
- JarEntry entry = j.getJarEntry("dtd/" + dtdName);
- if (entry == null) {
- entry = j.getJarEntry("org/jboss/metadata/" +
dtdName);
- }
-
- if (entry != null) {
- if (log.isDebugEnabled())
- log.debug("Found DTD locally: " +
entry.getName());
-
- return new InputSource(j.getInputStream(entry));
+ try {
+ JarEntry entry = j.getJarEntry("dtd/" + dtdName);
+ if (entry == null) {
+ entry = j.getJarEntry("org/jboss/metadata/" +
dtdName);
+ }
+
+ if (entry != null) {
+ if (log.isDebugEnabled())
+ log.debug("Found DTD locally: " +
entry.getName());
+
+ return new InputSource(j.getInputStream(entry));
+ }
+ } finally {
+ j.close();
}
}
}
commit 5cad7eabcfad901a4b1fc4673d8fa59ce5ad5de4
Author: Robert Buck <rbuck(a)redhat.com>
Date: Tue Aug 9 18:34:37 2011 -0400
[BZ 726435][coverity 13112, 13113, 13276, 13277, 13041, 13025, 13005, 13012] Fix
Coverity identified RESOURCE_LEAK; close some IO streams.
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/perspective/PerspectiveServerPluginManager.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/perspective/PerspectiveServerPluginManager.java
index 88153a6..104e85d 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/perspective/PerspectiveServerPluginManager.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/perspective/PerspectiveServerPluginManager.java
@@ -100,11 +100,15 @@ public class PerspectiveServerPluginManager extends
ServerPluginManager {
String name = null;
try {
JarFile pluginJarFile = new JarFile(env.getPluginUrl().getFile());
- for (JarEntry entry : Collections.list(pluginJarFile.entries())) {
- name = entry.getName();
- if (name.toLowerCase().endsWith(".war")) {
- deployWar(env, entry.getName(),
pluginJarFile.getInputStream(entry));
+ try {
+ for (JarEntry entry : Collections.list(pluginJarFile.entries())) {
+ name = entry.getName();
+ if (name.toLowerCase().endsWith(".war")) {
+ deployWar(env, entry.getName(),
pluginJarFile.getInputStream(entry));
+ }
}
+ } finally {
+ pluginJarFile.close();
}
} catch (Exception e) {
Throwable t = (e instanceof MBeanException) ? e.getCause() : e;
@@ -225,11 +229,15 @@ public class PerspectiveServerPluginManager extends
ServerPluginManager {
String name = null;
try {
JarFile plugin = new JarFile(env.getPluginUrl().getFile());
- for (JarEntry entry : Collections.list(plugin.entries())) {
- name = entry.getName();
- if (name.toLowerCase().endsWith(".war")) {
- undeployWar(getDeployFile(env, entry.getName()));
+ try {
+ for (JarEntry entry : Collections.list(plugin.entries())) {
+ name = entry.getName();
+ if (name.toLowerCase().endsWith(".war")) {
+ undeployWar(getDeployFile(env, entry.getName()));
+ }
}
+ } finally {
+ plugin.close();
}
} catch (Exception e) {
this.log.error("Failed to deploy " +
env.getPluginKey().getPluginName() + "#" + name, e);
diff --git
a/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/ModJKComponent.java
b/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/ModJKComponent.java
index 40d0f87..a4e1bcc 100644
--- a/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/ModJKComponent.java
+++ b/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/ModJKComponent.java
@@ -42,8 +42,6 @@ import org.rhq.plugins.apache.util.HttpdConfParser;
*/
public class ModJKComponent implements ResourceComponent<ApacheServerComponent> {
- private static final Log log = LogFactory.getLog(ModJKComponent.class);
-
private static final String OUTPUT_RESULT_PROP = "output";
public void start(ResourceContext<ApacheServerComponent>
parentResourceContext)
@@ -64,12 +62,12 @@ public class ModJKComponent implements
ResourceComponent<ApacheServerComponent>
* @param serverComponent The parents server component with the configuration
* @param params Params we got passed from the GUI
* @return The outcome of the operation
+ * @throws Exception see thrown exception for details; thrown exception summarizes
error
*/
public static OperationResult installModJk(ApacheServerComponent serverComponent,
Configuration params)
throws Exception {
StringBuilder builder = new StringBuilder();
- boolean errorSeen = false;
boolean needWorkersProps = false;
boolean needUriWorkers = false;
@@ -86,44 +84,48 @@ public class ModJKComponent implements
ResourceComponent<ApacheServerComponent>
cparser.parse(confPath);
// TODO back up original file
try {
- BufferedWriter writer = new BufferedWriter(new FileWriter(httpdConf, true));
-
- if (cparser.isModJkInstalled()) {
- builder.append("Mod_jk is already installed\n");
- if (cparser.getWorkerPropertiesFile() != null) {
- builder.append("Found a worker.properties file at
").append(cparser.getWorkerPropertiesFile());
- builder.append("\n");
- } else
+ BufferedWriter writer = null;
+ try {
+ writer = new BufferedWriter(new FileWriter(httpdConf, true));
+ if (cparser.isModJkInstalled()) {
+ builder.append("Mod_jk is already installed\n");
+ if (cparser.getWorkerPropertiesFile() != null) {
+ builder.append("Found a worker.properties file at
").append(cparser.getWorkerPropertiesFile());
+ builder.append("\n");
+ } else
+ needWorkersProps = true;
+
+ if (cparser.getUriWorkerLocation() != null) {
+ builder.append("Found a urimap file at
").append(cparser.getUriWorkerLocation());
+ } else
+ needUriWorkers = true;
+ } else {
+ builder.append("No mod_jk installed yet at
").append(confPath).append("\n");
+
+ writer.append("LoadModule jk_module modules/mod_jk.so"); //
TODO obtain modules location
+ writer.newLine();
+
+ builder.append(".. written a LoadModule line \n");
needWorkersProps = true;
-
- if (cparser.getUriWorkerLocation() != null) {
- builder.append("Found a urimap file at
").append(cparser.getUriWorkerLocation());
- } else
needUriWorkers = true;
- } else {
- builder.append("No mod_jk installed yet at
").append(confPath).append("\n");
-
- writer.append("LoadModule jk_module modules/mod_jk.so"); //
TODO obtain modules location
- writer.newLine();
-
- builder.append(".. written a LoadModule line \n");
- needWorkersProps = true;
- needUriWorkers = true;
+ }
+
+ if (needWorkersProps) {
+ writer.append("JkWorkersFile
").append("conf/workers.properties");
+ writer.newLine();
+ builder.append(".. installed worker.properties");
+ }
+ if (needUriWorkers) {
+ writer.append("JkMountFile
").append("conf/uriworkermap");
+ writer.newLine();
+ builder.append(".. installed uriworkermap");
+ }
+ } finally {
+ if (writer != null) {
+ // close automatically flushes!
+ writer.close();
+ }
}
-
- if (needWorkersProps) {
- writer.append("JkWorkersFile
").append("conf/workers.properties");
- writer.newLine();
- builder.append(".. installed worker.properties");
- }
- if (needUriWorkers) {
- writer.append("JkMountFile
").append("conf/uriworkermap");
- writer.newLine();
- builder.append(".. installed uriworkermap");
- }
- writer.flush();
- writer.close();
-
} catch (IOException e) {
builder.append("Error when installing mod_jk: \n");
builder.append(e.fillInStackTrace());
diff --git
a/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/augeas/AugeasConfigurationApache.java
b/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/augeas/AugeasConfigurationApache.java
index a3a715c..ba52e77 100644
---
a/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/augeas/AugeasConfigurationApache.java
+++
b/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/augeas/AugeasConfigurationApache.java
@@ -115,23 +115,28 @@ public class AugeasConfigurationApache extends
PluginDescriptorBasedAugeasConfig
if (fl.exists() && fl.isFile()) {
foundIncludes.add(fl.getAbsolutePath());
- FileInputStream fstream = new FileInputStream(fl);
- BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
- String strLine;
- while ((strLine = br.readLine()) != null) {
- Matcher m = includePattern.matcher(strLine);
- if (m.matches()) {
- String glob = m.group(1);
-
- module.addIncludedGlob(glob);
- loadIncludes(glob, foundIncludes);
+ BufferedReader br = null;
+ try {
+ br = new BufferedReader(new InputStreamReader(new
FileInputStream(fl)));
+ String strLine;
+ while ((strLine = br.readLine()) != null) {
+ Matcher m = includePattern.matcher(strLine);
+ if (m.matches()) {
+ String glob = m.group(1);
+
+ module.addIncludedGlob(glob);
+ loadIncludes(glob, foundIncludes);
+ }
+ Matcher serverRootMatcher = serverRootPattern.matcher(strLine);
+ if (serverRootMatcher.matches()) {
+ serverRootPath = serverRootMatcher.group(1);
+ }
}
- Matcher serverRootMatcher = serverRootPattern.matcher(strLine);
- if (serverRootMatcher.matches()) {
- serverRootPath = serverRootMatcher.group(1);
+ } finally {
+ if (br != null) {
+ br.close();
}
}
- br.close();
}
}
diff --git
a/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/ApplicationServerDiscoveryComponent.java
b/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/ApplicationServerDiscoveryComponent.java
index 3bf3b09..a08e977 100644
---
a/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/ApplicationServerDiscoveryComponent.java
+++
b/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/ApplicationServerDiscoveryComponent.java
@@ -146,9 +146,7 @@ public class ApplicationServerDiscoveryComponent implements
ResourceDiscoveryCom
} catch (IOException e) {
throw new InvalidPluginConfigurationException(e);
}
- DiscoveredResourceDetails resourceDetails =
createResourceDetails(discoveryContext, pluginConfig, processInfo,
- installInfo);
- return resourceDetails;
+ return createResourceDetails(discoveryContext, pluginConfig, processInfo,
installInfo);
}
@SuppressWarnings("unchecked")
@@ -413,8 +411,9 @@ public class ApplicationServerDiscoveryComponent implements
ResourceDiscoveryCom
private String getJnpURL(JBossInstanceInfo cmdLine, File installHome, File configDir)
{
File jnpServiceUrlFile = new File(configDir, "data/jnp-service.url");
if (jnpServiceUrlFile.exists() && jnpServiceUrlFile.canRead()) {
+ BufferedReader br = null;
try {
- BufferedReader br = new BufferedReader(new
FileReader(jnpServiceUrlFile));
+ br = new BufferedReader(new FileReader(jnpServiceUrlFile));
String jnpUrl = br.readLine();
if (jnpUrl != null) {
if (log.isDebugEnabled()) {
@@ -424,6 +423,14 @@ public class ApplicationServerDiscoveryComponent implements
ResourceDiscoveryCom
}
} catch (IOException ioe) {
// Nothing to do
+ } finally {
+ if (br != null) {
+ try {
+ br.close();
+ } catch (IOException e) {
+ // nada
+ }
+ }
}
}
diff --git
a/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/deploy/ManagedComponentDeployer.java
b/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/deploy/ManagedComponentDeployer.java
index 4315155..de6a174 100644
---
a/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/deploy/ManagedComponentDeployer.java
+++
b/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/deploy/ManagedComponentDeployer.java
@@ -146,8 +146,11 @@ public class ManagedComponentDeployer implements Deployer {
Manifest manifest;
if (manifestFile.exists()) {
FileInputStream inputStream = new FileInputStream(manifestFile);
- manifest = new Manifest(inputStream);
- inputStream.close();
+ try {
+ manifest = new Manifest(inputStream);
+ } finally {
+ inputStream.close();
+ }
} else {
File metaInf = new File(deploymentFile, "META-INF");
if (!metaInf.exists())
@@ -160,8 +163,11 @@ public class ManagedComponentDeployer implements Deployer {
Attributes attribs = manifest.getMainAttributes();
attribs.putValue("RHQ-Sha256", shaString);
FileOutputStream outputStream = new FileOutputStream(manifestFile);
- manifest.write(outputStream);
- outputStream.close();
+ try {
+ manifest.write(outputStream);
+ } finally {
+ outputStream.close();
+ }
} else {
LOG.error("Exploded deployment '" + deploymentFile
+ "' does not exist or is not a directory - unable
to add RHQ versioning metadata to META-INF/MANIFEST.MF.");
diff --git
a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseProcessDiscovery.java
b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseProcessDiscovery.java
index 1b05ae6..9d4c2f2 100644
---
a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseProcessDiscovery.java
+++
b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseProcessDiscovery.java
@@ -77,7 +77,7 @@ public class BaseProcessDiscovery extends AbstractBaseDiscovery
implements Resou
String serverName;
String psName = psr.getProcessScan().getName();
String description = discoveryContext.getResourceType().getDescription();
- String version = null;
+ String version;
//retrieve specific boot log file. Override for Standalone as server.log is
more appropriate
String bootLogFile = getLogFileFromCommandLine(commandLine);
@@ -232,9 +232,12 @@ public class BaseProcessDiscovery extends AbstractBaseDiscovery
implements Resou
try {
DocumentBuilder builder = factory.newDocumentBuilder();
InputStream is = new FileInputStream(hostXmlFile);
- Document document = builder.parse(is); // TODO keep this around
- hostName = document.getDocumentElement().getAttribute("name");
- is.close();
+ try {
+ Document document = builder.parse(is); // TODO keep this around
+ hostName = document.getDocumentElement().getAttribute("name");
+ } finally {
+ is.close();
+ }
} catch (Exception e) {
e.printStackTrace(); // TODO: Customise this generated block
}
commit 7877a3e5be5f8f0dfa657587a884b52e70ea1181
Author: Robert Buck <rbuck(a)redhat.com>
Date: Tue Aug 9 17:33:24 2011 -0400
[BZ 726435][coverity 13283] Fix Coverity identified RESOURCE_LEAK; close some IO
streams.
diff --git a/modules/core/domain/src/main/java/org/rhq/core/server/EntitySerializer.java
b/modules/core/domain/src/main/java/org/rhq/core/server/EntitySerializer.java
index 6e1f305..323a15c 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/server/EntitySerializer.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/server/EntitySerializer.java
@@ -252,14 +252,26 @@ public class EntitySerializer {
String tempDir = System.getProperty("java.io.tmpdir");
File tempFile = new File(tempDir, "entitySerializerTest.txt");
- ObjectOutput output = new ObjectOutputStream(new FileOutputStream(tempFile));
- writeExternalRemote(writeResource, output);
- output.close();
+ ObjectOutput output = null;
+ try {
+ output = new ObjectOutputStream(new FileOutputStream(tempFile));
+ writeExternalRemote(writeResource, output);
+ } finally {
+ if (output != null) {
+ output.close();
+ }
+ }
Resource readResource = new Resource();
- ObjectInput input = new ObjectInputStream(new FileInputStream(tempFile));
- readExternalRemote(readResource, input);
- input.close();
+ ObjectInput input = null;
+ try {
+ input = new ObjectInputStream(new FileInputStream(tempFile));
+ readExternalRemote(readResource, input);
+ } finally {
+ if (input != null) {
+ input.close();
+ }
+ }
// quick verification
System.out.println("AFTER");
commit e2f2f54d036091eeda96f18151c9fdc82a3ed728
Author: Robert Buck <rbuck(a)redhat.com>
Date: Tue Aug 9 11:50:19 2011 -0400
[BZ 726434] Fix io stream resource leak; also fixed a javadoc issue that caused
code-red.
diff --git
a/modules/plugins/jboss-as/src/main/java/org/rhq/plugins/jbossas/util/FileContentDelegate.java
b/modules/plugins/jboss-as/src/main/java/org/rhq/plugins/jbossas/util/FileContentDelegate.java
index 9628e25..6c4e83b 100644
---
a/modules/plugins/jboss-as/src/main/java/org/rhq/plugins/jbossas/util/FileContentDelegate.java
+++
b/modules/plugins/jboss-as/src/main/java/org/rhq/plugins/jbossas/util/FileContentDelegate.java
@@ -105,16 +105,22 @@ public class FileContentDelegate {
Manifest manifest;
if (manifestFile.exists()) {
FileInputStream inputStream = new FileInputStream(manifestFile);
- manifest = new Manifest(inputStream);
- inputStream.close();
+ try {
+ manifest = new Manifest(inputStream);
+ } finally {
+ inputStream.close();
+ }
} else {
manifest = new Manifest();
}
Attributes attribs = manifest.getMainAttributes();
attribs.putValue("RHQ-Sha256", shaString);
FileOutputStream outputStream = new FileOutputStream(manifestFile);
- manifest.write(outputStream);
- outputStream.close();
+ try {
+ manifest.write(outputStream);
+ } finally {
+ outputStream.close();
+ }
} else {
FileUtil.writeFile(content, contentFile);
}
diff --git
a/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/helper/FileContentDelegate.java
b/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/helper/FileContentDelegate.java
index 2087d5f..1d2b6b2 100644
---
a/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/helper/FileContentDelegate.java
+++
b/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/helper/FileContentDelegate.java
@@ -71,7 +71,7 @@ public class FileContentDelegate {
* Creates a new package described by the specified details. The destination of the
content in the provided input
* stream will be determined by the package name.
*
- * @param details describes the package being created
+ * @param contentFile the file to write the content to
* @param content content to be written for the package. NOTE this Stream will be
closed by this method.
* @param unzip if <code>true</code>, the content stream will be
treated like a ZIP file and be unzipped as
* it is written, using the package name as the base directory; if
<code>false</code> the
commit b65f00bca15817c5249c0c1e7e9da0a2bdd67331
Merge: 78ce519 cdd1964
Author: Robert Buck <rbuck(a)redhat.com>
Date: Tue Aug 9 11:47:01 2011 -0400
Merge branch 'master' into code-smell
* master: (195 commits)
Also pick the profile via dependent value.
Add dependent values for create child operations.
Re rpcTimeout, trap numeric exceptions and fallback if a user does not provide an
integer value.
Add rpc timeout capability so users can specify an override timeout via query string
parameters. The new query string parameter is rpcTimeout, the type an integer, and the
units are expressed in seconds.
[BZ 722600,726524] Update db-upgrade to add indexes for
RHQ_ALERT_CONDITION_LOG.CONDITION_ID and RHQ_MEASUREMENT_SCHED.RESOURCE_ID to optimize
queries.
[BZ 726524] Consider adding an index for the RHQ_ALERT_CONDITION_LOG.CONDITION_ID to
optimize queries.
[BZ 722600] Add index to RHQ_MEASUREMENT_SCHED.RESOURCE_ID column as recommended by
Oracle EM to improve performance.
The exported system settings are now directly backed by the actual system settings
properties so that no changes need to be made to the export classes when a new system
setting is added. The system settings importer now accepts configuration.
more work to make the integration-tests profile actually build.
A number of test apache upgrade test cases was mis-configured.
Test config reading / updating with the socket binding group and two bindings.
adding the common module to integration-tests so that the drift and as plugins
build.
make the specification of the httpd binary needed for the apache integration tests
slightly more flexible.
Remove some accidentally checked in files I noticed in the source tree.
Remove some accidentally checked in files I noticed in the source tree.
Taking out code that results in compile errors...
BZ720674 - adding a ResourceUpgradeFacet on the Agent discovery component to deal
with the RK format change mistakenly introduced in RHQ3 codebase.
Fix updating ListsOfMaps and disable the list of includes for now (AS7-1467)
Correcting the schema version in the pom file (after a bad merge).
Reverting more code wrongly updated during merge ...
...
commit 78ce51980e1fbb6ece062825c813722b46e4952c
Merge: fbc31a7 ec88d4b
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Mon Aug 1 08:42:38 2011 +0200
Merge branch 'master' into code-smell
commit fbc31a7aae1ffc7949789473bfe7a72c5777d862
Merge: b38642e c4a82bc
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Mon Aug 1 08:38:51 2011 +0200
Merge branch 'master' into code-smell