Index: /applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/tests/Coastlines.java
===================================================================
--- /applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/tests/Coastlines.java	(revision 18193)
+++ /applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/tests/Coastlines.java	(revision 18194)
@@ -6,12 +6,12 @@
 import java.util.*;
 
+import org.openstreetmap.josm.command.ChangeCommand;
+import org.openstreetmap.josm.command.Command;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
+import org.openstreetmap.josm.data.osm.Node;
 import org.openstreetmap.josm.data.osm.Way;
-import org.openstreetmap.josm.gui.progress.ProgressMonitor;
 import org.openstreetmap.josm.plugins.validator.Severity;
 import org.openstreetmap.josm.plugins.validator.Test;
 import org.openstreetmap.josm.plugins.validator.TestError;
-import org.openstreetmap.josm.plugins.validator.util.Bag;
-import org.openstreetmap.josm.plugins.validator.util.Util;
 
 /**
@@ -22,11 +22,10 @@
 public class Coastlines extends Test
 {
-    protected static int UNORDERED_COASTLINES = 901;
+    protected static int UNORDERED_COASTLINE = 901;
+    protected static int REVERSED_COASTLINE = 902;
+    protected static int UNCONNECTED_COASTLINE = 903;
 
-    /** All ways, grouped by cells */
-    Map<Point2D,List<Way>> _cellWays;
-    /** The already detected errors */
-    Bag<Way, Way> _errorWays;
-
+    private boolean fixable = false;
+    
     /**
      * Constructor
@@ -39,52 +38,90 @@
 
     @Override
-    public void startTest(ProgressMonitor monitor)
+    public void visit(Way w)
     {
-    	super.startTest(monitor);
-        _cellWays = new HashMap<Point2D,List<Way>>(1000);
-        _errorWays = new Bag<Way, Way>();
+        if(!w.isUsable() || w.isClosed())
+            return;
+
+        String natural = w.get("natural");
+        if(natural == null || !natural.equals("coastline"))
+            return;
+
+        Node f = w.firstNode();
+        Node l = w.lastNode();
+        Way prev = null;
+        Way next = null;
+
+        for (OsmPrimitive parent: this.backreferenceDataSet.getParents(f)) {
+            natural = parent.get("natural");
+            if (parent instanceof Way && !w.equals(parent) && (natural != null && "coastline".equals(natural))) {
+                prev = (Way)parent;
+                break;
+            }
+        }
+        for (OsmPrimitive parent: this.backreferenceDataSet.getParents(l)) {
+            natural = parent.get("natural");
+            if (parent instanceof Way && !w.equals(parent) && (natural != null && "coastline".equals(natural))) {
+                next = (Way)parent;
+                break;
+            }
+        }
+
+        List<OsmPrimitive> primitives = new ArrayList<OsmPrimitive>();
+        List<OsmPrimitive> highlight = new ArrayList<OsmPrimitive>();
+        primitives.add(w);
+
+        if (prev == null || next == null) {
+            if (prev == null)
+                highlight.add(f);
+            if (next == null)
+                highlight.add(l);
+
+            errors.add(new TestError(this, Severity.ERROR, tr("Unconnected coastline"),
+                                     UNCONNECTED_COASTLINE, primitives, highlight));
+        }
+
+        boolean fuo = (prev != null && !f.equals(prev.lastNode()));
+        boolean luo = (next != null && !l.equals(next.firstNode()));
+
+        if (fuo || luo) {
+            if (fuo && luo) {
+                errors.add(new TestError(this, Severity.ERROR, tr("Reversed coastline"),
+                                         REVERSED_COASTLINE, primitives));
+
+            } else {
+                if (fuo)
+                    highlight.add(f);
+                if (luo)
+                    highlight.add(l);
+
+                errors.add(new TestError(this, Severity.ERROR, tr("Unordered coastline"),
+                                         UNORDERED_COASTLINE, primitives, highlight));
+            }
+        }
     }
 
     @Override
-    public void endTest()
-    {
-    	super.endTest();
-        _cellWays = null;
-        _errorWays = null;
+    public Command fixError(TestError testError) {
+        if (isFixable(testError)) {
+            Way w = (Way) testError.getPrimitives().iterator().next();
+            Way wnew = new Way(w);
+
+            List<Node> nodesCopy = wnew.getNodes();
+            Collections.reverse(nodesCopy);
+            wnew.setNodes(nodesCopy);
+
+            return new ChangeCommand(w, wnew);
+        }
+
+        return null;
     }
 
     @Override
-    public void visit(Way w)
-    {
-        if( !w.isUsable() )
-            return;
+    public boolean isFixable(TestError testError) {
+        if (testError.getTester() instanceof Coastlines) {
+            return (testError.getCode() == REVERSED_COASTLINE);
+        }
 
-        String natural = w.get("natural");
-        if( natural == null || !natural.equals("coastline") )
-            return;
-
-        List<List<Way>> cellWays = Util.getWaysInCell(w, _cellWays);
-        for( List<Way> ways : cellWays)
-        {
-            for( Way w2 : ways)
-            {
-                if( _errorWays.contains(w, w2) || _errorWays.contains(w2, w) )
-                    continue;
-
-                String natural2 = w.get("natural");
-                if( natural2 == null || !natural2.equals("coastline") )
-                    continue;
-
-                if( w.getNodes().get(0).equals(w2.getNodes().get(0)) || w.getNodes().get(w.getNodesCount() - 1).equals(w2.getNodes().get(w2.getNodesCount() - 1)))
-                {
-                    List<OsmPrimitive> primitives = new ArrayList<OsmPrimitive>();
-                    primitives.add(w);
-                    primitives.add(w2);
-                    errors.add( new TestError(this, Severity.ERROR, tr("Unordered coastline"), UNORDERED_COASTLINES, primitives) );
-                    _errorWays.add(w, w2);
-                }
-            }
-            ways.add(w);
-        }
+        return false;
     }
 }
Index: /applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/tests/UnclosedWays.java
===================================================================
--- /applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/tests/UnclosedWays.java	(revision 18193)
+++ /applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/tests/UnclosedWays.java	(revision 18194)
@@ -50,18 +50,15 @@
     private String etype;
     private int mode;
-    private boolean force;
 
-    public void set(boolean f, int m, String text, String desc) {
+    public void set(int m, String text, String desc) {
         etype = MessageFormat.format(text, desc);
         type = tr(text, tr(desc));
         mode = m;
-        force = f;
     }
 
-    public void set(boolean f, int m, String text) {
+    public void set(int m, String text) {
         etype = text;
         type = tr(text);
         mode = m;
-        force = f;
     }
 
@@ -69,5 +66,4 @@
     public void visit(Way w) {
         String test;
-        force = false; /* force even if end-to-end distance is long */
         type = etype = null;
         mode = 0;
@@ -77,55 +73,54 @@
 
         test = w.get("natural");
-        if (test != null)
-            set(!"coastline".equals(test), 1101, marktr("natural type {0}"), test);
+        if (test != null && !"coastline".equals(test))
+            set(1101, marktr("natural type {0}"), test);
         test = w.get("landuse");
         if (test != null)
-            set(true, 1102, marktr("landuse type {0}"), test);
+            set(1102, marktr("landuse type {0}"), test);
         test = w.get("amenities");
         if (test != null)
-            set(true, 1103, marktr("amenities type {0}"), test);
+            set(1103, marktr("amenities type {0}"), test);
         test = w.get("sport");
         if (test != null && !test.equals("water_slide"))
-            set(true, 1104, marktr("sport type {0}"), test);
+            set(1104, marktr("sport type {0}"), test);
         test = w.get("tourism");
         if (test != null)
-            set(true, 1105, marktr("tourism type {0}"), test);
+            set(1105, marktr("tourism type {0}"), test);
         test = w.get("shop");
         if (test != null)
-            set(true, 1106, marktr("shop type {0}"), test);
+            set(1106, marktr("shop type {0}"), test);
         test = w.get("leisure");
         if (test != null)
-            set(true, 1107, marktr("leisure type {0}"), test);
+            set(1107, marktr("leisure type {0}"), test);
         test = w.get("waterway");
         if (test != null && test.equals("riverbank"))
-            set(true, 1108, marktr("waterway type {0}"), test);
+            set(1108, marktr("waterway type {0}"), test);
         Boolean btest = OsmUtils.getOsmBoolean(w.get("building"));
         if (btest != null && btest)
-            set(true, 1120, marktr("building"));
+            set(1120, marktr("building"));
         btest = OsmUtils.getOsmBoolean(w.get("area"));
         if (btest != null && btest)
-            set(true, 1130, marktr("area"));
+            set(1130, marktr("area"));
 
-        if (type != null && !w.isClosed())
-        {
+        if (type != null && !w.isClosed()) {
             for (OsmPrimitive parent: this.backreferenceDataSet.getParents(w)) {
                 if (parent instanceof Relation && "multipolygon".equals(parent.get("type")))
                     return;
             }
-            Node f = w.getNode(0);
-            Node l = w.getNode(w.getNodesCount() - 1);
-            if(force || f.getCoor().greatCircleDistance(l.getCoor()) < 10000)
-            {
-                List<OsmPrimitive> primitives = new ArrayList<OsmPrimitive>();
-                List<OsmPrimitive> highlight = new ArrayList<OsmPrimitive>();
-                primitives.add(w);
-                // The important parts of an unclosed way are the first and
-                // the last node which should be connected, therefore we highlight them
-                highlight.add(f);
-                highlight.add(l);
-                errors.add(new TestError(this, Severity.WARNING, tr("Unclosed way"), type, etype, mode, primitives,
-                        highlight));
-                _errorWays.add(w, w);
-            }
+            Node f = w.firstNode();
+            Node l = w.lastNode();
+
+            List<OsmPrimitive> primitives = new ArrayList<OsmPrimitive>();
+            List<OsmPrimitive> highlight = new ArrayList<OsmPrimitive>();
+            primitives.add(w);
+
+            // The important parts of an unclosed way are the first and
+            // the last node which should be connected, therefore we highlight them
+            highlight.add(f);
+            highlight.add(l);
+
+            errors.add(new TestError(this, Severity.WARNING, tr("Unclosed way"),
+                            type, etype, mode, primitives, highlight));
+            _errorWays.add(w, w);
         }
     }
