Index: trunk/src/org/openstreetmap/josm/data/AutosaveTask.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/AutosaveTask.java	(revision 7029)
+++ trunk/src/org/openstreetmap/josm/data/AutosaveTask.java	(revision 7033)
@@ -157,9 +157,7 @@
             try {
                 if (result.createNewFile()) {
-                    try {
-                        File pidFile = new File(autosaveDir, filename+".pid");
-                        PrintStream ps = new PrintStream(pidFile, "UTF-8");
+                    File pidFile = new File(autosaveDir, filename+".pid");
+                    try (PrintStream ps = new PrintStream(pidFile, "UTF-8")) {
                         ps.println(ManagementFactory.getRuntimeMXBean().getName());
-                        Utils.close(ps);
                     } catch (Throwable t) {
                         Main.error(t);
@@ -305,6 +303,5 @@
                 File pidFile = getPidFile(file);
                 if (pidFile.exists()) {
-                    try {
-                        BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(pidFile), Utils.UTF_8));
+                    try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(pidFile), Utils.UTF_8))) {
                         try {
                             String jvmId = reader.readLine();
Index: trunk/src/org/openstreetmap/josm/data/CustomConfigurator.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/CustomConfigurator.java	(revision 7029)
+++ trunk/src/org/openstreetmap/josm/data/CustomConfigurator.java	(revision 7033)
@@ -427,5 +427,7 @@
                 String fileDir = file.getParentFile().getAbsolutePath();
                 if (fileDir!=null) engine.eval("scriptDir='"+normalizeDirName(fileDir) +"';");
-                openAndReadXML(new BufferedInputStream(new FileInputStream(file)));
+                try (InputStream is = new BufferedInputStream(new FileInputStream(file))) {
+                    openAndReadXML(is);
+                }
             } catch (Exception ex) {
                 log("Error reading custom preferences: " + ex.getMessage());
@@ -445,6 +447,4 @@
             } catch (Exception ex) {
                 log("Error reading custom preferences: "+ex.getMessage());
-            } finally {
-                Utils.close(is);
             }
             log("-- Reading complete --");
@@ -460,5 +460,5 @@
                 engine.eval("homeDir='"+normalizeDirName(Main.pref.getPreferencesDir()) +"';");
                 engine.eval("josmVersion="+Version.getInstance().getVersion()+";");
-                String className =  CustomConfigurator.class.getName();
+                String className = CustomConfigurator.class.getName();
                 engine.eval("API.messageBox="+className+".messageBox");
                 engine.eval("API.askText=function(text) { return String("+className+".askForText(text));}");
Index: trunk/src/org/openstreetmap/josm/data/Preferences.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/Preferences.java	(revision 7029)
+++ trunk/src/org/openstreetmap/josm/data/Preferences.java	(revision 7033)
@@ -11,4 +11,5 @@
 import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.OutputStreamWriter;
@@ -719,6 +720,5 @@
 
     /**
-     * Called after every put. In case of a problem, do nothing but output the error
-     * in log.
+     * Called after every put. In case of a problem, do nothing but output the error in log.
      */
     public void save() throws IOException {
@@ -736,8 +736,8 @@
         }
 
-        final PrintWriter out = new PrintWriter(new OutputStreamWriter(
-                new FileOutputStream(prefFile + "_tmp"), Utils.UTF_8), false);
-        out.print(toXML(false));
-        Utils.close(out);
+        try (PrintWriter out = new PrintWriter(new OutputStreamWriter(
+                new FileOutputStream(prefFile + "_tmp"), Utils.UTF_8), false)) {
+            out.print(toXML(false));
+        }
 
         File tmpFile = new File(prefFile + "_tmp");
@@ -748,5 +748,4 @@
         setCorrectPermissions(backupFile);
     }
-
 
     private void setCorrectPermissions(File file) {
@@ -761,12 +760,9 @@
         settingsMap.clear();
         File pref = getPreferenceFile();
-        BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(pref), Utils.UTF_8));
-        try {
+        try (BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(pref), Utils.UTF_8))) {
             validateXML(in);
-            Utils.close(in);
-            in = new BufferedReader(new InputStreamReader(new FileInputStream(pref), Utils.UTF_8));
+        }
+        try (BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(pref), Utils.UTF_8))) {
             fromXML(in);
-        } finally {
-            Utils.close(in);
         }
         updateSystemProperties();
@@ -1359,7 +1355,9 @@
     public void validateXML(Reader in) throws Exception {
         SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
-        Schema schema = factory.newSchema(new StreamSource(new MirroredInputStream("resource://data/preferences.xsd")));
-        Validator validator = schema.newValidator();
-        validator.validate(new StreamSource(in));
+        try (InputStream xsdStream = new MirroredInputStream("resource://data/preferences.xsd")) {
+            Schema schema = factory.newSchema(new StreamSource(xsdStream));
+            Validator validator = schema.newValidator();
+            validator.validate(new StreamSource(in));
+        }
     }
 
Index: trunk/src/org/openstreetmap/josm/data/Version.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/Version.java	(revision 7029)
+++ trunk/src/org/openstreetmap/josm/data/Version.java	(revision 7033)
@@ -38,12 +38,9 @@
         String s = null;
         try {
-            BufferedReader in = Utils.openURLReader(resource);
             StringBuilder sb = new StringBuilder();
-            try {
+            try (BufferedReader in = Utils.openURLReader(resource)) {
                 for (String line = in.readLine(); line != null; line = in.readLine()) {
                     sb.append(line).append("\n");
                 }
-            } finally {
-                Utils.close(in);
             }
             s = sb.toString();
Index: trunk/src/org/openstreetmap/josm/data/imagery/WmsCache.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/imagery/WmsCache.java	(revision 7029)
+++ trunk/src/org/openstreetmap/josm/data/imagery/WmsCache.java	(revision 7033)
@@ -111,48 +111,39 @@
     private String getCacheDirectory(String url) {
         String cacheDirName = null;
-        InputStream fis = null;
-        OutputStream fos = null;
-        try {
-            Properties layersIndex = new Properties();
-            File layerIndexFile = new File(cacheDirPath(), LAYERS_INDEX_FILENAME);
-            try {
-                fis = new FileInputStream(layerIndexFile);
-                layersIndex.load(fis);
-            } catch (FileNotFoundException e) {
-                Main.error("Unable to load layers index for wms cache (file " + layerIndexFile + " not found)");
+        Properties layersIndex = new Properties();
+        File layerIndexFile = new File(cacheDirPath(), LAYERS_INDEX_FILENAME);
+        try (InputStream fis = new FileInputStream(layerIndexFile)) {
+            layersIndex.load(fis);
+        } catch (FileNotFoundException e) {
+            Main.error("Unable to load layers index for wms cache (file " + layerIndexFile + " not found)");
+        } catch (IOException e) {
+            Main.error("Unable to load layers index for wms cache");
+            Main.error(e);
+        }
+
+        for (Object propKey: layersIndex.keySet()) {
+            String s = (String)propKey;
+            if (url.equals(layersIndex.getProperty(s))) {
+                cacheDirName = s;
+                break;
+            }
+        }
+
+        if (cacheDirName == null) {
+            int counter = 0;
+            while (true) {
+                counter++;
+                if (!layersIndex.keySet().contains(String.valueOf(counter))) {
+                    break;
+                }
+            }
+            cacheDirName = String.valueOf(counter);
+            layersIndex.setProperty(cacheDirName, url);
+            try (OutputStream fos = new FileOutputStream(layerIndexFile)) {
+                layersIndex.store(fos, "");
             } catch (IOException e) {
-                Main.error("Unable to load layers index for wms cache");
+                Main.error("Unable to save layer index for wms cache");
                 Main.error(e);
             }
-
-            for (Object propKey: layersIndex.keySet()) {
-                String s = (String)propKey;
-                if (url.equals(layersIndex.getProperty(s))) {
-                    cacheDirName = s;
-                    break;
-                }
-            }
-
-            if (cacheDirName == null) {
-                int counter = 0;
-                while (true) {
-                    counter++;
-                    if (!layersIndex.keySet().contains(String.valueOf(counter))) {
-                        break;
-                    }
-                }
-                cacheDirName = String.valueOf(counter);
-                layersIndex.setProperty(cacheDirName, url);
-                try {
-                    fos = new FileOutputStream(layerIndexFile);
-                    layersIndex.store(fos, "");
-                } catch (IOException e) {
-                    Main.error("Unable to save layer index for wms cache");
-                    Main.error(e);
-                }
-            }
-        } finally {
-            Utils.close(fos);
-            Utils.close(fis);
         }
 
@@ -181,5 +172,8 @@
                     WmsCacheType.class.getClassLoader());
             Unmarshaller unmarshaller = context.createUnmarshaller();
-            WmsCacheType cacheEntries = (WmsCacheType)unmarshaller.unmarshal(new FileInputStream(indexFile));
+            WmsCacheType cacheEntries;
+            try (InputStream is = new FileInputStream(indexFile)) {
+                cacheEntries = (WmsCacheType)unmarshaller.unmarshal(is);
+            }
             totalFileSize = cacheEntries.getTotalFileSize();
             if (cacheEntries.getTileSize() != tileSize) {
@@ -292,5 +286,7 @@
                     WmsCacheType.class.getClassLoader());
             Marshaller marshaller = context.createMarshaller();
-            marshaller.marshal(index, new FileOutputStream(new File(cacheDir, INDEX_FILENAME)));
+            try (OutputStream fos = new FileOutputStream(new File(cacheDir, INDEX_FILENAME))) {
+                marshaller.marshal(index, fos);
+            }
         } catch (Exception e) {
             Main.error("Failed to save wms-cache file");
@@ -302,5 +298,4 @@
         return new File(cacheDir, projection.cacheDirectory + "/" + entry.filename);
     }
-
 
     private BufferedImage loadImage(ProjectionEntries projectionEntries, CacheEntry entry) throws IOException {
@@ -524,9 +519,6 @@
             totalFileSize += imageFile.length();
         } else {
-            OutputStream os = new BufferedOutputStream(new FileOutputStream(imageFile));
-            try {
+            try (OutputStream os = new BufferedOutputStream(new FileOutputStream(imageFile))) {
                 totalFileSize += Utils.copyStream(imageData, os);
-            } finally {
-                Utils.close(os);
             }
         }
Index: trunk/src/org/openstreetmap/josm/data/projection/Projections.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/projection/Projections.java	(revision 7029)
+++ trunk/src/org/openstreetmap/josm/data/projection/Projections.java	(revision 7033)
@@ -132,13 +132,13 @@
     private static void loadInits() {
         Pattern epsgPattern = Pattern.compile("<(\\d+)>(.*)<>");
-        BufferedReader r = null;
-        try {
+        try (
             InputStream in = new MirroredInputStream("resource://data/projection/epsg");
-            r = new BufferedReader(new InputStreamReader(in, Utils.UTF_8));
+            BufferedReader r = new BufferedReader(new InputStreamReader(in, Utils.UTF_8));
+        ) {
             String line, lastline = "";
             while ((line = r.readLine()) != null) {
                 line = line.trim();
                 if (!line.startsWith("#") && !line.isEmpty()) {
-                    if (!lastline.startsWith("#")) throw new AssertionError();
+                    if (!lastline.startsWith("#")) throw new AssertionError("EPSG file seems corrupted");
                     String name = lastline.substring(1).trim();
                     Matcher m = epsgPattern.matcher(line);
@@ -153,6 +153,4 @@
         } catch (IOException ex) {
             throw new RuntimeException(ex);
-        } finally {
-            Utils.close(r);
         }
     }
Index: trunk/src/org/openstreetmap/josm/data/projection/datum/NTV2GridShiftFileWrapper.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/projection/datum/NTV2GridShiftFileWrapper.java	(revision 7029)
+++ trunk/src/org/openstreetmap/josm/data/projection/datum/NTV2GridShiftFileWrapper.java	(revision 7033)
@@ -48,6 +48,5 @@
     public NTV2GridShiftFile getShiftFile() {
         if (instance == null) {
-            try {
-                InputStream is = new MirroredInputStream(gridFileName);
+            try (InputStream is = new MirroredInputStream(gridFileName)) {
                 instance = new NTV2GridShiftFile();
                 instance.loadGridShiftFile(is, false);
@@ -58,4 +57,3 @@
         return instance;
     }
-
 }
Index: trunk/src/org/openstreetmap/josm/data/validation/OsmValidator.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/validation/OsmValidator.java	(revision 7029)
+++ trunk/src/org/openstreetmap/josm/data/validation/OsmValidator.java	(revision 7033)
@@ -171,7 +171,5 @@
             File file = new File(getValidatorDir() + "ignorederrors");
             if (file.exists()) {
-                BufferedReader in = null;
-                try {
-                    in = new BufferedReader(new InputStreamReader(new FileInputStream(file), Utils.UTF_8));
+                try (BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file), Utils.UTF_8))) {
                     for (String line = in.readLine(); line != null; line = in.readLine()) {
                         ignoredErrors.add(line);
@@ -181,6 +179,4 @@
                 } catch (final IOException e) {
                     Main.error(e);
-                } finally {
-                    Utils.close(in);
                 }
             }
@@ -197,7 +193,6 @@
 
     public static void saveIgnoredErrors() {
-        PrintWriter out = null;
-        try {
-            out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(getValidatorDir() + "ignorederrors"), Utils.UTF_8), false);
+        try (PrintWriter out = new PrintWriter(new OutputStreamWriter(
+                new FileOutputStream(getValidatorDir() + "ignorederrors"), Utils.UTF_8), false)) {
             for (String e : ignoredErrors) {
                 out.println(e);
@@ -205,6 +200,4 @@
         } catch (IOException e) {
             Main.error(e);
-        } finally {
-            Utils.close(out);
         }
     }
Index: trunk/src/org/openstreetmap/josm/data/validation/tests/MapCSSTagChecker.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/validation/tests/MapCSSTagChecker.java	(revision 7029)
+++ trunk/src/org/openstreetmap/josm/data/validation/tests/MapCSSTagChecker.java	(revision 7033)
@@ -453,9 +453,6 @@
                     Main.info(tr("Adding {0} to tag checker", i));
                 }
-                MirroredInputStream s = new MirroredInputStream(i);
-                try {
+                try (MirroredInputStream s = new MirroredInputStream(i)) {
                     addMapCSS(new BufferedReader(UTFInputStreamReader.create(s)));
-                } finally {
-                    Utils.close(s);
                 }
             } catch (IOException ex) {
Index: trunk/src/org/openstreetmap/josm/data/validation/tests/OpeningHourTest.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/validation/tests/OpeningHourTest.java	(revision 7029)
+++ trunk/src/org/openstreetmap/josm/data/validation/tests/OpeningHourTest.java	(revision 7033)
@@ -5,4 +5,5 @@
 
 import java.io.InputStreamReader;
+import java.io.Reader;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -51,20 +52,23 @@
         super.initialize();
         if (ENGINE != null) {
-            ENGINE.eval(new InputStreamReader(new MirroredInputStream("resource://data/validator/opening_hours.js"), Utils.UTF_8));
-            // fake country/state to not get errors on holidays
-            ENGINE.eval("var nominatimJSON = {address: {state: 'Bayern', country_code: 'de'}};");
-            ENGINE.eval(
-                    "var oh = function (value, mode) {" +
-                    " try {" +
-                    "    var r= new opening_hours(value, nominatimJSON, mode);" +
-                    "    r.getErrors = function() {return [];};" +
-                    "    return r;" +
-                    "  } catch(err) {" +
-                    "    return {" +
-                    "      getWarnings: function() {return [];}," +
-                    "      getErrors: function() {return [err.toString()]}" +
-                    "    };" +
-                    "  }" +
-                    "};");
+            try (Reader reader = new InputStreamReader(
+                    new MirroredInputStream("resource://data/validator/opening_hours.js"), Utils.UTF_8)) {
+                ENGINE.eval(reader);
+                // fake country/state to not get errors on holidays
+                ENGINE.eval("var nominatimJSON = {address: {state: 'Bayern', country_code: 'de'}};");
+                ENGINE.eval(
+                        "var oh = function (value, mode) {" +
+                        " try {" +
+                        "    var r= new opening_hours(value, nominatimJSON, mode);" +
+                        "    r.getErrors = function() {return [];};" +
+                        "    return r;" +
+                        "  } catch(err) {" +
+                        "    return {" +
+                        "      getWarnings: function() {return [];}," +
+                        "      getErrors: function() {return [err.toString()]}" +
+                        "    };" +
+                        "  }" +
+                        "};");
+            }
         } else {
             Main.warn("Unable to initialize OpeningHourTest because no JavaScript engine has been found");
Index: trunk/src/org/openstreetmap/josm/data/validation/tests/TagChecker.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/validation/tests/TagChecker.java	(revision 7029)
+++ trunk/src/org/openstreetmap/josm/data/validation/tests/TagChecker.java	(revision 7033)
@@ -54,5 +54,4 @@
 import org.openstreetmap.josm.tools.GBC;
 import org.openstreetmap.josm.tools.MultiMap;
-import org.openstreetmap.josm.tools.Utils;
 
 /**
@@ -165,9 +164,8 @@
         String errorSources = "";
         for (String source : Main.pref.getCollection(PREF_SOURCES, DEFAULT_SOURCES)) {
-            BufferedReader reader = null;
-            try {
+            try (
                 MirroredInputStream s = new MirroredInputStream(source);
-                reader = new BufferedReader(UTFInputStreamReader.create(s));
-
+                BufferedReader reader = new BufferedReader(UTFInputStreamReader.create(s));
+            ) {
                 String okValue = null;
                 boolean tagcheckerfile = false;
@@ -242,6 +240,4 @@
             } catch (IOException e) {
                 errorSources += source + "\n";
-            } finally {
-                Utils.close(reader);
             }
         }
