Index: /trunk/src/org/openstreetmap/josm/data/cache/JCSCachedTileLoaderJob.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/data/cache/JCSCachedTileLoaderJob.java	(revision 10557)
+++ /trunk/src/org/openstreetmap/josm/data/cache/JCSCachedTileLoaderJob.java	(revision 10558)
@@ -391,11 +391,6 @@
             } else {
                 attributes.setError(e);
-                attributes.setResponseCode(499); // set dummy error code
-                boolean doCache = isResponseLoadable(null, 499, null) || cacheAsEmpty(); //generic 499 error code returned
-                if (doCache) {
-                    cacheData = createCacheEntry(new byte[]{});
-                    cache.put(getCacheKey(), createCacheEntry(new byte[]{}), attributes);
-                }
-                return doCache;
+                attributes.setResponseCode(599); // set dummy error code, greater than 500 so it will be not cached
+                return false;
             }
 
Index: /trunk/test/unit/org/openstreetmap/josm/data/cache/JCSCachedTileLoaderJobTest.java
===================================================================
--- /trunk/test/unit/org/openstreetmap/josm/data/cache/JCSCachedTileLoaderJobTest.java	(revision 10557)
+++ /trunk/test/unit/org/openstreetmap/josm/data/cache/JCSCachedTileLoaderJobTest.java	(revision 10558)
@@ -3,4 +3,5 @@
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 
 import java.io.IOException;
@@ -13,4 +14,5 @@
 import org.junit.Test;
 import org.openstreetmap.josm.JOSMFixture;
+import org.openstreetmap.josm.data.cache.ICachedLoaderListener.LoadResult;
 
 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
@@ -23,17 +25,16 @@
     private static class TestCachedTileLoaderJob extends JCSCachedTileLoaderJob<String, CacheEntry> {
         private String url;
+        private String key;
 
-        TestCachedTileLoaderJob(String url) throws IOException {
+        TestCachedTileLoaderJob(String url, String key) throws IOException {
             super(getCache(), 30000, 30000, null);
+
             this.url = url;
-        }
-
-        private static ICacheAccess<String, CacheEntry> getCache() throws IOException {
-         return JCSCacheManager.getCache("test");
+            this.key = key;
         }
 
         @Override
         public String getCacheKey() {
-            return "cachekey" + url;
+            return key;
         }
 
@@ -56,4 +57,5 @@
         private CacheEntryAttributes attributes;
         private boolean ready;
+        private LoadResult result;
 
         @Override
@@ -61,4 +63,5 @@
             this.attributes = attributes;
             this.ready = true;
+            this.result = result;
             this.notifyAll();
         }
@@ -100,5 +103,6 @@
     @SuppressFBWarnings(value = "WA_NOT_IN_LOOP")
     public void testUnknownHost() throws IOException, InterruptedException {
-        TestCachedTileLoaderJob job = new TestCachedTileLoaderJob("http://unkownhost.unkownhost/unkown");
+        String key = "key_unknown_host";
+        TestCachedTileLoaderJob job = new TestCachedTileLoaderJob("http://unkownhost.unkownhost/unkown", key);
         Listener listener = new Listener();
         job.submit(listener, true);
@@ -109,4 +113,22 @@
         }
         assertEquals("java.net.UnknownHostException: unkownhost.unkownhost", listener.attributes.getErrorMessage());
+        assertEquals(LoadResult.FAILURE, listener.result); // because response will be cached, and that is checked below
+
+        ICacheAccess<String, CacheEntry> cache = getCache();
+        CacheEntry e = new CacheEntry(new byte[]{0,1,2,3});
+        CacheEntryAttributes attributes = new CacheEntryAttributes();
+        attributes.setExpirationTime(2);
+        cache.put(key, e, attributes);
+
+        job = new TestCachedTileLoaderJob("http://unkownhost.unkownhost/unkown", key);
+        listener = new Listener();
+        job.submit(listener, true);
+        synchronized (listener) {
+            if (!listener.ready) {
+                listener.wait();
+            }
+        }
+        assertEquals(LoadResult.SUCCESS, listener.result);
+        assertFalse(job.isCacheElementValid());
     }
 
@@ -125,5 +147,9 @@
 
     private static TestCachedTileLoaderJob getStatusLoaderJob(int responseCode) throws IOException {
-        return new TestCachedTileLoaderJob("http://httpstat.us/" + responseCode);
+        return new TestCachedTileLoaderJob("http://httpstat.us/" + responseCode, "key_" + responseCode);
+    }
+
+    private static ICacheAccess<String, CacheEntry> getCache() throws IOException {
+        return JCSCacheManager.getCache("test");
     }
 }
