Index: trunk/src/org/openstreetmap/josm/data/cache/BufferedImageCacheEntry.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/cache/BufferedImageCacheEntry.java	(revision 8487)
+++ trunk/src/org/openstreetmap/josm/data/cache/BufferedImageCacheEntry.java	(revision 8488)
@@ -20,4 +20,7 @@
     private transient volatile BufferedImage img = null;
     private transient volatile boolean writtenToDisk = false;
+    // we need to have separate control variable, to know, if we already tried to load the image, as img might be null
+    // after we loaded image, as for example, when image file is malformed (eg. HTML file)
+    private transient volatile boolean imageLoaded = false;
 
     /**
@@ -37,12 +40,13 @@
      */
     public BufferedImage getImage() throws IOException {
-        if (img != null)
+        if (imageLoaded)
             return img;
         synchronized(this) {
-            if (img != null)
+            if (imageLoaded)
                 return img;
             byte[] content = getContent();
             if (content != null && content.length > 0) {
                 img = ImageIO.read(new ByteArrayInputStream(content));
+                imageLoaded = true;
 
                 if (writtenToDisk)
Index: trunk/src/org/openstreetmap/josm/data/imagery/TMSCachedTileLoaderJob.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/imagery/TMSCachedTileLoaderJob.java	(revision 8487)
+++ trunk/src/org/openstreetmap/josm/data/imagery/TMSCachedTileLoaderJob.java	(revision 8488)
@@ -193,4 +193,8 @@
                         if (content != null && content.length > 0) {
                             tile.loadImage(new ByteArrayInputStream(content));
+                            if (tile.getImage() == null) {
+                                tile.setError(tr("Could not load image from tile server"));
+                                status = false;
+                            }
                         }
                     }
@@ -242,7 +246,12 @@
                 }
 
-                if (data != null && data.getImage() != null) {
-                    tile.setImage(data.getImage());
-                    tile.finishLoading();
+                if (data != null) {
+                    if (data.getImage() != null) {
+                        tile.setImage(data.getImage());
+                        tile.finishLoading();
+                    } else {
+                        // we had some data, but we didn't get any image. Malformed image?
+                        tile.setError(tr("Could not load image from tile server"));
+                    }
                 }
                 if (isNoTileAtZoom()) {
