Use try with resources
authorGintas Grigelionis <gintas@apache.org>
Fri, 10 Aug 2018 12:05:16 +0000 (14:05 +0200)
committerGintas Grigelionis <gintas@apache.org>
Fri, 10 Aug 2018 12:07:03 +0000 (14:07 +0200)
org.apache.ivyde.eclipse/src/java/org/apache/ivyde/internal/eclipse/CachedIvy.java

index 3932aca..7ce3646 100644 (file)
@@ -253,35 +253,19 @@ public abstract class CachedIvy {
         } else {
             IvyDEMessage.verbose(propFiles.size() + " property file(s) to load");
             for (String file : propFiles) {
-                InputStream is;
                 Path p = new Path(file);
                 IvyDEMessage.debug("Loading property file " + p);
-                if (getProject() != null && !p.isAbsolute()) {
-                    try {
-                        is = new FileInputStream(getProject().getLocation().append(file).toFile());
-                    } catch (FileNotFoundException e) {
-                        throw new IvyDEException("Property file not found", "The property file '"
-                                + file + "' could not be found", e);
-                    }
-                } else {
-                    try {
-                        is = new FileInputStream(file);
-                    } catch (FileNotFoundException e) {
-                        throw new IvyDEException("Property file not found", "The property file '"
-                                + file + "' was not found", e);
-                    }
-                }
+                String propFile = (getProject() != null && !p.isAbsolute())
+                        ? getProject().getLocation().append(file).toString() : file;
                 Properties props = new Properties();
-                try {
+                try (InputStream is = new FileInputStream(propFile)) {
                     props.load(is);
+                } catch (FileNotFoundException e) {
+                    throw new IvyDEException("Property file not found", "The property file '"
+                            + propFile + "' was not found", e);
                 } catch (IOException e) {
-                    throw new IvyDEException("Not a property file", "The property file '" + file
-                            + "' could not be loaded", e);
-                }
-                try {
-                    is.close();
-                } catch (IOException e) {
-                    // don't care
+                    throw new IvyDEException("Not a property file", "The property file '"
+                            + propFile + "' could not be loaded", e);
                 }
 
                 for (String key : props.stringPropertyNames()) {