Changeset 8488 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2015-06-12T22:51:43+02:00 (9 years ago)
Author:
wiktorn
Message:

Properly handle situation, when tile server returns something else than image file but still gives http status code 200 (like html error page). Closes #11553

Location:
trunk/src/org/openstreetmap/josm/data
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/cache/BufferedImageCacheEntry.java

    r8470 r8488  
    2020    private transient volatile BufferedImage img = null;
    2121    private transient volatile boolean writtenToDisk = false;
     22    // we need to have separate control variable, to know, if we already tried to load the image, as img might be null
     23    // after we loaded image, as for example, when image file is malformed (eg. HTML file)
     24    private transient volatile boolean imageLoaded = false;
    2225
    2326    /**
     
    3740     */
    3841    public BufferedImage getImage() throws IOException {
    39         if (img != null)
     42        if (imageLoaded)
    4043            return img;
    4144        synchronized(this) {
    42             if (img != null)
     45            if (imageLoaded)
    4346                return img;
    4447            byte[] content = getContent();
    4548            if (content != null && content.length > 0) {
    4649                img = ImageIO.read(new ByteArrayInputStream(content));
     50                imageLoaded = true;
    4751
    4852                if (writtenToDisk)
  • trunk/src/org/openstreetmap/josm/data/imagery/TMSCachedTileLoaderJob.java

    r8459 r8488  
    193193                        if (content != null && content.length > 0) {
    194194                            tile.loadImage(new ByteArrayInputStream(content));
     195                            if (tile.getImage() == null) {
     196                                tile.setError(tr("Could not load image from tile server"));
     197                                status = false;
     198                            }
    195199                        }
    196200                    }
     
    242246                }
    243247
    244                 if (data != null && data.getImage() != null) {
    245                     tile.setImage(data.getImage());
    246                     tile.finishLoading();
     248                if (data != null) {
     249                    if (data.getImage() != null) {
     250                        tile.setImage(data.getImage());
     251                        tile.finishLoading();
     252                    } else {
     253                        // we had some data, but we didn't get any image. Malformed image?
     254                        tile.setError(tr("Could not load image from tile server"));
     255                    }
    247256                }
    248257                if (isNoTileAtZoom()) {
Note: See TracChangeset for help on using the changeset viewer.