Index: trunk/src/org/openstreetmap/josm/data/AutosaveTask.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/AutosaveTask.java	(revision 3458)
+++ trunk/src/org/openstreetmap/josm/data/AutosaveTask.java	(revision 3461)
@@ -25,4 +25,5 @@
 import org.openstreetmap.josm.data.osm.event.DataSetListenerAdapter;
 import org.openstreetmap.josm.data.osm.event.DataSetListenerAdapter.Listener;
+import org.openstreetmap.josm.data.preferences.BooleanProperty;
 import org.openstreetmap.josm.data.preferences.IntegerProperty;
 import org.openstreetmap.josm.gui.MapView;
@@ -41,8 +42,9 @@
     private static final String DELETED_LAYERS_DIR = "autosave/deleted_layers";
 
-
+    public static final BooleanProperty PROP_AUTOSAVE_ENABLED = new BooleanProperty("autosave.enabled", true);
     public static final IntegerProperty PROP_FILES_PER_LAYER = new IntegerProperty("autosave.filesPerLayer", 1);
     public static final IntegerProperty PROP_DELETED_LAYERS = new IntegerProperty("autosave.deletedLayersBackupCount", 5);
     public static final IntegerProperty PROP_INTERVAL = new IntegerProperty("autosave.interval", 5 * 60);
+    public static final IntegerProperty PROP_INDEX_LIMIT = new IntegerProperty("autosave.index-limit", 1000);
 
     private static class AutosaveLayerInfo {
@@ -59,5 +61,5 @@
     private final List<AutosaveLayerInfo> layersInfo = new ArrayList<AutosaveLayerInfo>();
     private Timer timer;
-    private Object layersLock = new Object();
+    private final Object layersLock = new Object();
     private final Deque<File> deletedLayers = new LinkedList<File>();
 
@@ -136,4 +138,6 @@
                 else {
                     System.out.println(tr("Unable to create file {0}, other filename will be used", result.getAbsolutePath()));
+                    if (index > PROP_INDEX_LIMIT.get())
+                        throw new IOException("index limit exceeded");
                 }
             } catch (IOException e) {
@@ -278,4 +282,9 @@
     }
 
+    public void dicardUnsavedLayers() {
+        for (File f: getUnsavedLayersFiles()) {
+            f.renameTo(new File(deletedLayersDir, f.getName()));
+        }
+    }
 
 }
Index: trunk/src/org/openstreetmap/josm/data/preferences/IntegerProperty.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/preferences/IntegerProperty.java	(revision 3458)
+++ trunk/src/org/openstreetmap/josm/data/preferences/IntegerProperty.java	(revision 3461)
@@ -22,4 +22,20 @@
     }
 
+    /**
+     * parses and saves an integer value
+     * @param value the value to be parsed
+     * @return true - preference value has changed
+     *         false - parsing failed or preference value has not changed
+     */
+    public boolean parseAndPut(String value) {
+        Integer intVal;
+        try {
+            intVal = Integer.parseInt(value);
+        } catch (NumberFormatException ex) {
+            return false;
+        }
+        return put(intVal);
+    }
+
     public String getKey() {
         return key;
