Index: trunk/src/org/openstreetmap/josm/tools/CheckParameterUtil.java
===================================================================
--- trunk/src/org/openstreetmap/josm/tools/CheckParameterUtil.java	(revision 5979)
+++ trunk/src/org/openstreetmap/josm/tools/CheckParameterUtil.java	(revision 5980)
@@ -4,4 +4,6 @@
 import java.text.MessageFormat;
 
+import org.openstreetmap.josm.data.coor.EastNorth;
+import org.openstreetmap.josm.data.coor.LatLon;
 import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
 import org.openstreetmap.josm.data.osm.PrimitiveId;
@@ -10,5 +12,5 @@
  * This utility class provides a collection of static helper methods for checking
  * parameters at run-time.
- *
+ * @ince 2711
  */
 public class CheckParameterUtil {
@@ -16,4 +18,10 @@
     private CheckParameterUtil(){}
 
+    /**
+     * Ensures an OSM primitive ID is valid
+     * @param id The id to check
+     * @param parameterName The parameter name
+     * @throws IllegalArgumentException if the primitive ID is not valid (negative or zero)
+     */
     public static void ensureValidPrimitiveId(PrimitiveId id, String parameterName) throws IllegalArgumentException {
         ensureParameterNotNull(id, parameterName);
@@ -22,4 +30,36 @@
     }
 
+    /**
+     * Ensures lat/lon coordinates are valid
+     * @param latlon The lat/lon to check
+     * @param parameterName The parameter name
+     * @throws IllegalArgumentException if the lat/lon are {@code null} or not valid
+     * @since 5980
+     */
+    public static void ensureValidCoordinates(LatLon latlon, String parameterName) throws IllegalArgumentException {
+        ensureParameterNotNull(latlon, parameterName);
+        if (!latlon.isValid())
+            throw new IllegalArgumentException(MessageFormat.format("Expected valid lat/lon for parameter ''{0}'', got {1}", parameterName, latlon));
+    }
+
+    /**
+     * Ensures east/north coordinates are valid
+     * @param eastnorth The east/north to check
+     * @param parameterName The parameter name
+     * @throws IllegalArgumentException if the east/north are {@code null} or not valid
+     * @since 5980
+     */
+    public static void ensureValidCoordinates(EastNorth eastnorth, String parameterName) throws IllegalArgumentException {
+        ensureParameterNotNull(eastnorth, parameterName);
+        if (!eastnorth.isValid())
+            throw new IllegalArgumentException(MessageFormat.format("Expected valid east/north for parameter ''{0}'', got {1}", parameterName, eastnorth));
+    }
+
+    /**
+     * Ensures a version number is valid
+     * @param version The version to check
+     * @param parameterName The parameter name
+     * @throws IllegalArgumentException if the version is not valid (negative)
+     */
     public static void ensureValidVersion(long version, String parameterName) throws IllegalArgumentException {
         if (version < 0)
@@ -27,5 +67,11 @@
     }
 
-    public static void ensureParameterNotNull(Object value, String parameterName) {
+    /**
+     * Ensures a parameter is not {@code null}
+     * @param value The parameter to check
+     * @param parameterName The parameter name
+     * @throws IllegalArgumentException if the parameter is {@code null}
+     */
+    public static void ensureParameterNotNull(Object value, String parameterName) throws IllegalArgumentException {
         if (value == null)
             throw new IllegalArgumentException(MessageFormat.format("Parameter ''{0}'' must not be null", parameterName));
@@ -33,7 +79,10 @@
 
     /**
-     * can find line number in the stack trace, so parameter name is optional
+     * Ensures a parameter is not {@code null}. Can find line number in the stack trace, so parameter name is optional
+     * @param value The parameter to check
+     * @throws IllegalArgumentException if the parameter is {@code null}
+     * @since 3871
      */
-    public static void ensureParameterNotNull(Object value) {
+    public static void ensureParameterNotNull(Object value) throws IllegalArgumentException {
         if (value == null)
             throw new IllegalArgumentException("Parameter must not be null");
Index: trunk/src/org/openstreetmap/josm/tools/Geometry.java
===================================================================
--- trunk/src/org/openstreetmap/josm/tools/Geometry.java	(revision 5979)
+++ trunk/src/org/openstreetmap/josm/tools/Geometry.java	(revision 5980)
@@ -247,7 +247,11 @@
      * @return EastNorth null if no intersection was found, the EastNorth coordinates of the intersection otherwise
      */
-    public static EastNorth getSegmentSegmentIntersection(
-            EastNorth p1, EastNorth p2,
-            EastNorth p3, EastNorth p4) {
+    public static EastNorth getSegmentSegmentIntersection(EastNorth p1, EastNorth p2, EastNorth p3, EastNorth p4) {
+        
+        CheckParameterUtil.ensureValidCoordinates(p1, "p1");
+        CheckParameterUtil.ensureValidCoordinates(p2, "p2");
+        CheckParameterUtil.ensureValidCoordinates(p3, "p3");
+        CheckParameterUtil.ensureValidCoordinates(p4, "p4");
+        
         double x1 = p1.getX();
         double y1 = p1.getY();
@@ -284,7 +288,15 @@
      * Finds the intersection of two lines of infinite length.
      * @return EastNorth null if no intersection was found, the coordinates of the intersection otherwise
+     * @throws IllegalArgumentException if a parameter is null or without valid coordinates
      */
     public static EastNorth getLineLineIntersection(EastNorth p1, EastNorth p2, EastNorth p3, EastNorth p4) {
 
+        CheckParameterUtil.ensureValidCoordinates(p1, "p1");
+        CheckParameterUtil.ensureValidCoordinates(p2, "p2");
+        CheckParameterUtil.ensureValidCoordinates(p3, "p3");
+        CheckParameterUtil.ensureValidCoordinates(p4, "p4");
+        
+        if (!p1.isValid()) throw new IllegalArgumentException();
+        
         // Convert line from (point, point) form to ax+by=c
         double a1 = p2.getY() - p1.getY();
@@ -305,4 +317,10 @@
 
     public static boolean segmentsParallel(EastNorth p1, EastNorth p2, EastNorth p3, EastNorth p4) {
+
+        CheckParameterUtil.ensureValidCoordinates(p1, "p1");
+        CheckParameterUtil.ensureValidCoordinates(p2, "p2");
+        CheckParameterUtil.ensureValidCoordinates(p3, "p3");
+        CheckParameterUtil.ensureValidCoordinates(p4, "p4");
+
         // Convert line from (point, point) form to ax+by=c
         double a1 = p2.getY() - p1.getY();
@@ -384,4 +402,9 @@
      */
     public static boolean angleIsClockwise(EastNorth commonNode, EastNorth firstNode, EastNorth secondNode) {
+        
+        CheckParameterUtil.ensureValidCoordinates(commonNode, "commonNode");
+        CheckParameterUtil.ensureValidCoordinates(firstNode, "firstNode");
+        CheckParameterUtil.ensureValidCoordinates(secondNode, "secondNode");
+        
         double dy1 = (firstNode.getY() - commonNode.getY());
         double dy2 = (secondNode.getY() - commonNode.getY());
@@ -583,4 +606,8 @@
      */
     public static double getSegmentAngle(EastNorth p1, EastNorth p2) {
+        
+        CheckParameterUtil.ensureValidCoordinates(p1, "p1");
+        CheckParameterUtil.ensureValidCoordinates(p2, "p2");
+        
         return Math.atan2(p2.north() - p1.north(), p2.east() - p1.east());
     }
@@ -595,4 +622,9 @@
      */
     public static double getCornerAngle(EastNorth p1, EastNorth p2, EastNorth p3) {
+        
+        CheckParameterUtil.ensureValidCoordinates(p1, "p1");
+        CheckParameterUtil.ensureValidCoordinates(p2, "p2");
+        CheckParameterUtil.ensureValidCoordinates(p3, "p3");
+        
         Double result = getSegmentAngle(p2, p1) - getSegmentAngle(p2, p3);
         if (result <= -Math.PI) {
@@ -651,6 +683,10 @@
      * @return Intersection coordinate or null
      */
-    public static EastNorth getSegmentAltituteIntersection(EastNorth sp1,
-            EastNorth sp2, EastNorth ap) {
+    public static EastNorth getSegmentAltituteIntersection(EastNorth sp1, EastNorth sp2, EastNorth ap) {
+        
+        CheckParameterUtil.ensureValidCoordinates(sp1, "sp1");
+        CheckParameterUtil.ensureValidCoordinates(sp2, "sp2");
+        CheckParameterUtil.ensureValidCoordinates(ap, "ap");
+
         Double segmentLenght = sp1.distance(sp2);
         Double altitudeAngle = getSegmentAngle(sp1, sp2) + Math.PI / 2;
