Hao Zhong created ARIES-1730:
--------------------------------
Summary: It is better to close a file stream with
Key: ARIES-1730
URL: https://issues.apache.org/jira/browse/ARIES-1730
Project: Aries
Issue Type: Improvement
Components: JMX
Affects Versions: jmx-1.1.6
Reporter: Hao Zhong
Priority: Minor
The Framework_installBundleFromURL method has the following code:
{code}
try {
inputStream = createStream(url);
Bundle bundle = context.installBundle(location, inputStream);
return bundle.getBundleId();
} catch (Exception e) {
IOException ioex = new IOException("Installation of a bundle with
location " + location + " failed with the message: " + e.getMessage());
ioex.initCause(e);
throw ioex;
} finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException ioe) {
}
}
}
{code}
Here, the method handles the inputStream by itself. It is better to use the
implemented method in org.apache.aries.application.utils.filesystem.IOUtils.
Indeed, ARIES-622 fixed a similar problem. The original code is:
{code}
public DeploymentMetadata parseDeploymentMetadata(IFile src) throws IOException
{
InputStream is = src.open();
try {
return parseDeploymentMetadata(is);
} finally {
is.close();
}
}
{code}
The fixed code is
{code}
import org.apache.aries.application.utils.filesystem.IOUtils;
...
public DeploymentMetadata parseDeploymentMetadata(IFile src) throws IOException
{
InputStream is = src.open();
try {
return parseDeploymentMetadata(is);
} finally {
IOUtils.close(is);
}
}
{code}
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)