Index: trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPainter.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPainter.java	(revision 5373)
+++ trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPainter.java	(revision 5374)
@@ -403,8 +403,8 @@
 
     public void drawTextOnPath(Way way, TextElement text) {
-        if (text == null)
+        if (way == null || text == null)
             return;
         String name = text.getString(way);
-        if (name == null || name.equals(""))
+        if (name == null || name.isEmpty())
             return;
 
@@ -438,4 +438,7 @@
         double[] p1 = pointAt(t1, poly, pathLength);
         double[] p2 = pointAt(t2, poly, pathLength);
+        
+        if (p1 == null || p2 == null)
+        	return;
 
         double angleOffset;
@@ -462,9 +465,11 @@
             double t = tStart + offsetSign * (rect.getX() + rect.getWidth()/2) / pathLength;
             double[] p = pointAt(t, poly, pathLength);
-            AffineTransform trfm = AffineTransform.getTranslateInstance(p[0] - rect.getX(), p[1]);
-            trfm.rotate(p[2]+angleOffset);
-            double off = -rect.getY() - rect.getHeight()/2 + text.yOffset;
-            trfm.translate(-rect.getWidth()/2, off);
-            gv.setGlyphTransform(i, trfm);
+            if (p != null) {
+	            AffineTransform trfm = AffineTransform.getTranslateInstance(p[0] - rect.getX(), p[1]);
+	            trfm.rotate(p[2]+angleOffset);
+	            double off = -rect.getY() - rect.getHeight()/2 + text.yOffset;
+	            trfm.translate(-rect.getWidth()/2, off);
+	            gv.setGlyphTransform(i, trfm);
+            }
         }
         if (text.haloRadius != null) {
@@ -488,5 +493,5 @@
         double segLen;
 
-        // Yes, it is ineffecient to iterate from the beginning for each glyph.
+        // Yes, it is inefficient to iterate from the beginning for each glyph.
         // Can be optimized if it turns out to be slow.
         for (int i = 1; i < poly.npoints; ++i) {
@@ -498,5 +503,6 @@
                 continue;
             }
-            return new double[] {poly.xpoints[i-1]+(totalLen - curLen)/segLen*dx,
+            return new double[] {
+            		poly.xpoints[i-1]+(totalLen - curLen)/segLen*dx,
                     poly.ypoints[i-1]+(totalLen - curLen)/segLen*dy,
                     Math.atan2(dy, dx)};
