Index: trunk/src/org/openstreetmap/josm/actions/relation/RecentRelationsAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/relation/RecentRelationsAction.java	(revision 9673)
+++ trunk/src/org/openstreetmap/josm/actions/relation/RecentRelationsAction.java	(revision 9674)
@@ -5,8 +5,9 @@
 
 import java.awt.Component;
+import java.awt.Rectangle;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.awt.event.KeyEvent;
-import java.awt.Rectangle;
+import java.util.Collections;
 import java.util.List;
 
@@ -19,11 +20,11 @@
 import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.data.osm.Relation;
-import org.openstreetmap.josm.gui.layer.Layer;
-import org.openstreetmap.josm.gui.layer.OsmDataLayer;
-import org.openstreetmap.josm.gui.layer.OsmDataLayer.CommandQueueListener;
 import org.openstreetmap.josm.gui.DefaultNameFormatter;
 import org.openstreetmap.josm.gui.MapView;
 import org.openstreetmap.josm.gui.MapView.LayerChangeListener;
 import org.openstreetmap.josm.gui.SideButton;
+import org.openstreetmap.josm.gui.layer.Layer;
+import org.openstreetmap.josm.gui.layer.OsmDataLayer;
+import org.openstreetmap.josm.gui.layer.OsmDataLayer.CommandQueueListener;
 import org.openstreetmap.josm.tools.Shortcut;
 
@@ -31,5 +32,5 @@
  * Action for accessing recent relations.
  */
-public class RecentRelationsAction implements ActionListener, CommandQueueListener, LayerChangeListener{
+public class RecentRelationsAction implements ActionListener, CommandQueueListener, LayerChangeListener {
 
     private final SideButton editButton;
@@ -39,4 +40,5 @@
     /**
      * Constructs a new <code>RecentRelationsAction</code>.
+     * @param editButton edit button
      */
     public RecentRelationsAction(SideButton editButton) {
@@ -61,13 +63,22 @@
     }
 
+    /**
+     * Enables arrow button.
+     */
     public void enableArrow() {
         arrow.setEnabled(getLastRelation() != null);
     }
 
+    /**
+     * Returns the last relation.
+     * @return the last relation
+     */
     public static Relation getLastRelation() {
         List<Relation> recentRelations = getRecentRelationsOnActiveLayer();
-        if (recentRelations == null || recentRelations.isEmpty()) return null;
+        if (recentRelations == null || recentRelations.isEmpty())
+            return null;
         for (Relation relation: recentRelations) {
-            if (!isRelationListable(relation)) continue;
+            if (!isRelationListable(relation))
+                continue;
             return relation;
         }
@@ -75,4 +86,9 @@
     }
 
+    /**
+     * Determines if the given relation is listable in last relations.
+     * @param relation relation
+     * @return {@code true} if relation is non null, not deleted, and in current dataset
+     */
     public static boolean isRelationListable(Relation relation) {
         return relation != null &&
@@ -106,9 +122,14 @@
     }
 
+    /**
+     * Returns the list of recent relations on active layer.
+     * @return the list of recent relations on active layer
+     */
     public static List<Relation> getRecentRelationsOnActiveLayer() {
-        if (Main.map == null || Main.map.mapView == null) return null;
-        Layer activeLayer = Main.map.mapView.getActiveLayer();
+        if (!Main.isDisplayingMapView())
+            return Collections.emptyList();
+        Layer activeLayer = Main.main.getActiveLayer();
         if (!(activeLayer instanceof OsmDataLayer)) {
-            return null;
+            return Collections.emptyList();
         } else {
             return ((OsmDataLayer) activeLayer).getRecentRelations();
@@ -117,18 +138,14 @@
 
     protected static class RecentRelationsPopupMenu extends JPopupMenu {
-        public static void launch(Component parent, KeyStroke keystroke) {
-            List<Relation> recentRelations = getRecentRelationsOnActiveLayer();
-            JPopupMenu menu = new RecentRelationsPopupMenu(recentRelations, keystroke);
-            Rectangle r = parent.getBounds();
-            menu.show(parent, r.x, r.y + r.height);
-        }
-
         /**
-         * Constructs a new {@code SearchPopupMenu}.
+         * Constructs a new {@code RecentRelationsPopupMenu}.
+         * @param recentRelations list of recent relations
+         * @param keystroke key stroke for the first menu item
          */
         public RecentRelationsPopupMenu(List<Relation> recentRelations, KeyStroke keystroke) {
             boolean first = true;
             for (Relation relation: recentRelations) {
-                if (!isRelationListable(relation)) continue;
+                if (!isRelationListable(relation))
+                    continue;
                 JMenuItem menuItem = new RecentRelationsMenuItem(relation);
                 if (first) {
@@ -138,4 +155,9 @@
                 add(menuItem);
             }
+        }
+
+        public static void launch(Component parent, KeyStroke keystroke) {
+            Rectangle r = parent.getBounds();
+            new RecentRelationsPopupMenu(getRecentRelationsOnActiveLayer(), keystroke).show(parent, r.x, r.y + r.height);
         }
     }
Index: trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java	(revision 9673)
+++ trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java	(revision 9674)
@@ -26,5 +26,4 @@
 import java.util.HashSet;
 import java.util.LinkedHashMap;
-import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
@@ -426,6 +425,5 @@
 
     /**
-     * merges the primitives in dataset <code>from</code> into the dataset of
-     * this layer
+     * merges the primitives in dataset <code>from</code> into the dataset of this layer
      *
      * @param from  the source data set
@@ -437,4 +435,5 @@
             visitor.merge(progressMonitor);
         } catch (DataIntegrityProblemException e) {
+            Main.error(e);
             JOptionPane.showMessageDialog(
                     Main.parent,
@@ -747,10 +746,8 @@
         for (String key : possibleKeys) {
             String value = p.get(key);
-            if (value != null) {
-                // Sanity checks
-                if (!GpxConstants.PT_FIX.equals(gpxKey) || GpxConstants.FIX_VALUES.contains(value)) {
-                    wpt.put(gpxKey, value);
-                    break;
-                }
+            // Sanity checks
+            if (value != null && (!GpxConstants.PT_FIX.equals(gpxKey) || GpxConstants.FIX_VALUES.contains(value))) {
+                wpt.put(gpxKey, value);
+                break;
             }
         }
@@ -779,6 +776,6 @@
         @Override
         public void actionPerformed(ActionEvent e) {
-            final GpxData data = toGpxData();
-            final GpxLayer gpxLayer = new GpxLayer(data, tr("Converted from: {0}", getName()));
+            final GpxData gpxData = toGpxData();
+            final GpxLayer gpxLayer = new GpxLayer(gpxData, tr("Converted from: {0}", getName()));
             if (getAssociatedFile() != null) {
                 final String filename = getAssociatedFile().getName().replaceAll(Pattern.quote(".gpx.osm") + "$", "") + ".gpx";
@@ -786,6 +783,6 @@
             }
             Main.main.addLayer(gpxLayer);
-            if (Main.pref.getBoolean("marker.makeautomarkers", true) && !data.waypoints.isEmpty()) {
-                Main.main.addLayer(new MarkerLayer(data, tr("Converted from: {0}", getName()), null, gpxLayer));
+            if (Main.pref.getBoolean("marker.makeautomarkers", true) && !gpxData.waypoints.isEmpty()) {
+                Main.main.addLayer(new MarkerLayer(gpxData, tr("Converted from: {0}", getName()), null, gpxLayer));
             }
             Main.main.removeLayer(OsmDataLayer.this);
@@ -804,12 +801,12 @@
             return true;
 
-        boolean layer_bounds_point = false;
+        boolean layerBoundsPoint = false;
         for (DataSource src : this.data.dataSources) {
             if (src.bounds.contains(coor)) {
-                layer_bounds_point = true;
+                layerBoundsPoint = true;
                 break;
             }
         }
-        return layer_bounds_point;
+        return layerBoundsPoint;
     }
 
@@ -942,41 +939,37 @@
     @Override
     public boolean checkSaveConditions() {
-        if (isDataSetEmpty()) {
-            if (1 != GuiHelper.runInEDTAndWaitAndReturn(new Callable<Integer>() {
-                @Override
-                public Integer call() {
-                    ExtendedDialog dialog = new ExtendedDialog(
-                            Main.parent,
-                            tr("Empty document"),
-                            new String[] {tr("Save anyway"), tr("Cancel")}
-                    );
-                    dialog.setContent(tr("The document contains no data."));
-                    dialog.setButtonIcons(new String[] {"save", "cancel"});
-                    return dialog.showDialog().getValue();
-                }
-            })) {
-                return false;
-            }
-        }
-
-        ConflictCollection conflicts = getConflicts();
-        if (conflicts != null && !conflicts.isEmpty()) {
-            if (1 != GuiHelper.runInEDTAndWaitAndReturn(new Callable<Integer>() {
-                @Override
-                public Integer call() {
-                    ExtendedDialog dialog = new ExtendedDialog(
-                            Main.parent,
-                            /* I18N: Display title of the window showing conflicts */
-                            tr("Conflicts"),
-                            new String[] {tr("Reject Conflicts and Save"), tr("Cancel")}
-                    );
-                    dialog.setContent(
-                            tr("There are unresolved conflicts. Conflicts will not be saved and handled as if you rejected all. Continue?"));
-                    dialog.setButtonIcons(new String[] {"save", "cancel"});
-                    return dialog.showDialog().getValue();
-                }
-            })) {
-                return false;
-            }
+        if (isDataSetEmpty() && 1 != GuiHelper.runInEDTAndWaitAndReturn(new Callable<Integer>() {
+            @Override
+            public Integer call() {
+                ExtendedDialog dialog = new ExtendedDialog(
+                        Main.parent,
+                        tr("Empty document"),
+                        new String[] {tr("Save anyway"), tr("Cancel")}
+                );
+                dialog.setContent(tr("The document contains no data."));
+                dialog.setButtonIcons(new String[] {"save", "cancel"});
+                return dialog.showDialog().getValue();
+            }
+        })) {
+            return false;
+        }
+
+        ConflictCollection conflictsCol = getConflicts();
+        if (conflictsCol != null && !conflictsCol.isEmpty() && 1 != GuiHelper.runInEDTAndWaitAndReturn(new Callable<Integer>() {
+            @Override
+            public Integer call() {
+                ExtendedDialog dialog = new ExtendedDialog(
+                        Main.parent,
+                        /* I18N: Display title of the window showing conflicts */
+                        tr("Conflicts"),
+                        new String[] {tr("Reject Conflicts and Save"), tr("Cancel")}
+                );
+                dialog.setContent(
+                        tr("There are unresolved conflicts. Conflicts will not be saved and handled as if you rejected all. Continue?"));
+                dialog.setButtonIcons(new String[] {"save", "cancel"});
+                return dialog.showDialog().getValue();
+            }
+        })) {
+            return false;
         }
         return true;
@@ -1006,5 +999,6 @@
         if (file == null && isRenamed()) {
             String filename = Main.pref.get("lastDirectory") + '/' + getName();
-            if (!OsmImporter.FILE_FILTER.acceptName(filename)) filename = filename + '.' + extension;
+            if (!OsmImporter.FILE_FILTER.acceptName(filename))
+                filename = filename + '.' + extension;
             file = new File(filename);
         }
Index: trunk/src/org/openstreetmap/josm/gui/widgets/FileChooserManager.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/widgets/FileChooserManager.java	(revision 9673)
+++ trunk/src/org/openstreetmap/josm/gui/widgets/FileChooserManager.java	(revision 9674)
@@ -284,10 +284,10 @@
      */
     public FileChooserManager doCreateFileChooser() {
-        File file = new File(curDir);
+        File f = new File(curDir);
         // Use native dialog is preference is set, unless an unsupported selection mode is specifically wanted
         if (PROP_USE_NATIVE_FILE_DIALOG.get() && NativeFileChooser.supportsSelectionMode(selectionMode)) {
-            fc = new NativeFileChooser(file);
+            fc = new NativeFileChooser(f);
         } else {
-            fc = new SwingFileChooser(file);
+            fc = new SwingFileChooser(f);
         }
 
@@ -332,5 +332,6 @@
      */
     public AbstractFileChooser openFileChooser(Component parent) {
-        if (fc == null) doCreateFileChooser();
+        if (fc == null)
+            doCreateFileChooser();
 
         if (parent == null) {
@@ -347,9 +348,6 @@
         }
 
-        if (!open) {
-            File file = fc.getSelectedFile();
-            if (!SaveActionBase.confirmOverwrite(file)) {
-                return null;
-            }
+        if (!open && !SaveActionBase.confirmOverwrite(fc.getSelectedFile())) {
+            return null;
         }
         return fc;
@@ -357,5 +355,6 @@
 
     /**
-     * Opens the file chooser dialog, then checks if filename has the given extension. If not, adds the extension and asks for overwrite if filename exists.
+     * Opens the file chooser dialog, then checks if filename has the given extension.
+     * If not, adds the extension and asks for overwrite if filename exists.
      *
      * @return the {@code File} or {@code null} if the user cancelled the dialog.
