Skip to content

Commit

Permalink
Merge pull request #3051 from AmilaSamith/issue-fix-299
Browse files Browse the repository at this point in the history
[MI-4.2.0] Fix to close input streams explicitly
  • Loading branch information
AmilaSamith authored Feb 8, 2024
2 parents c1edc8b + 61a97fc commit d7ba885
Showing 1 changed file with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,8 @@ private boolean lookupUtil(String key, URL url) {
if ("file".equals(url.getProtocol())) {
try {
if (new File(url.toURI()).exists()) {
try {
url.openStream();
try (InputStream inputStream = url.openStream()) {
// This try-with-resources block is used to check whether the resource is accessible
} catch (IOException e) {
log.error("Error occurred while accessing registry resource: " + key, e);
return true;
Expand Down Expand Up @@ -415,8 +415,8 @@ public RegistryEntry getRegistryEntry(String key) {
try {
URL url = new URL(resolveRegistryURI(key));
if ("file".equals(url.getProtocol())) {
try {
url.openStream();
try (InputStream inputStream = url.openStream()) {
// This try-with-resources block is used to check whether the resource is accessible
} catch (IOException e) {
log.error("Error occurred while accessing registry resource: " + key, e);
return null;
Expand Down Expand Up @@ -1133,8 +1133,8 @@ private void addConfigProperty(String name, String value) {
registryType = MicroIntegratorRegistryConstants.LOCAL_HOST_REGISTRY;

//Check existence of the target location
try {
rootPathUrl.openStream();
try (InputStream inputStream = rootPathUrl.openStream()) {
// This try-with-resources block is used to check whether the resource is accessible
} catch (IOException e) {
// If the registry is filesystem based, user may have provided the URI relative to the CARBON_HOME
if (log.isDebugEnabled()) {
Expand All @@ -1147,8 +1147,7 @@ private void addConfigProperty(String name, String value) {
}
pathFromCarbonHome = rootPathUrl.getProtocol() + ":" + pathFromCarbonHome + value;
rootPathUrl = new URL(pathFromCarbonHome);
try {
rootPathUrl.openStream();
try (InputStream inputStream = rootPathUrl.openStream()) {
value = pathFromCarbonHome;
} catch (IOException e1) {
//Unable to open input stream to target location
Expand Down

0 comments on commit d7ba885

Please sign in to comment.