Index: trunk/src/org/openstreetmap/josm/gui/layer/AbstractTileSourceLayer.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/layer/AbstractTileSourceLayer.java	(revision 18924)
+++ trunk/src/org/openstreetmap/josm/gui/layer/AbstractTileSourceLayer.java	(revision 18926)
@@ -2,4 +2,5 @@
 package org.openstreetmap.josm.gui.layer;
 
+import static org.openstreetmap.josm.tools.I18n.marktr;
 import static org.openstreetmap.josm.tools.I18n.tr;
 
@@ -10,4 +11,5 @@
 import java.awt.Graphics;
 import java.awt.Graphics2D;
+import java.awt.GridBagConstraints;
 import java.awt.GridBagLayout;
 import java.awt.Image;
@@ -179,4 +181,5 @@
 
     private static final BooleanProperty POPUP_MENU_ENABLED = new BooleanProperty(PREFERENCE_PREFIX + ".popupmenu", true);
+    private static final String ERROR_STRING = marktr("Error");
 
     /*
@@ -343,5 +346,5 @@
             panel.add(new JLabel(entry.get(0) + ':'), GBC.std());
             panel.add(GBC.glue(5, 0), GBC.std());
-            panel.add(createTextField(entry.get(1)), GBC.eol().fill(GBC.HORIZONTAL));
+            panel.add(createTextField(entry.get(1)), GBC.eol().fill(GridBagConstraints.HORIZONTAL));
         }
         return panel;
@@ -469,9 +472,9 @@
                 content.add(Arrays.asList(tr("Loaded"), tr(Boolean.toString(tile.isLoaded()))));
                 content.add(Arrays.asList(tr("Loading"), tr(Boolean.toString(tile.isLoading()))));
-                content.add(Arrays.asList(tr("Error"), tr(Boolean.toString(tile.hasError()))));
+                content.add(Arrays.asList(tr(ERROR_STRING), tr(Boolean.toString(tile.hasError()))));
                 for (List<String> entry: content) {
                     panel.add(new JLabel(entry.get(0) + ':'), GBC.std());
                     panel.add(GBC.glue(5, 0), GBC.std());
-                    panel.add(layer.createTextField(entry.get(1)), GBC.eol().fill(GBC.HORIZONTAL));
+                    panel.add(layer.createTextField(entry.get(1)), GBC.eol().fill(GridBagConstraints.HORIZONTAL));
                 }
 
@@ -483,5 +486,5 @@
                         value = Instant.ofEpochMilli(Long.parseLong(value)).toString();
                     }
-                    panel.add(layer.createTextField(value), GBC.eol().fill(GBC.HORIZONTAL));
+                    panel.add(layer.createTextField(value), GBC.eol().fill(GridBagConstraints.HORIZONTAL));
 
                 }
@@ -559,5 +562,5 @@
 
         event.getMapView().addMouseListener(adapter);
-        MapView.addZoomChangeListener(this);
+        NavigatableComponent.addZoomChangeListener(this);
 
         if (this instanceof NativeScaleLayer && Boolean.TRUE.equals(NavigatableComponent.PROP_ZOOM_SCALE_FOLLOW_NATIVE_RES_AT_LOAD.get())) {
@@ -1206,6 +1209,6 @@
                     Logging.debug(e);
                 }
-                if (!errorMessage.startsWith("Error") && !errorMessage.startsWith(tr("Error"))) {
-                    errorMessage = tr("Error") + ": " + errorMessage;
+                if (!errorMessage.startsWith(ERROR_STRING) && !errorMessage.startsWith(tr(ERROR_STRING))) {
+                    errorMessage = tr(ERROR_STRING) + ": " + errorMessage;
                 }
                 myDrawString(g, errorMessage, x + 2, texty);
@@ -1264,5 +1267,10 @@
 
         private boolean tooLarge() {
-            return tileCache == null || size() > tileCache.getCacheSize();
+            try {
+                return tileCache == null || size() > tileCache.getCacheSize();
+            } catch (ArithmeticException arithmeticException) {
+                Logging.trace(arithmeticException);
+                return true;
+            }
         }
 
@@ -1424,5 +1432,10 @@
                         List<Tile> allTiles = this.allExistingTiles();
                         TileSetInfo newInfo = new TileSetInfo();
-                        newInfo.hasLoadingTiles = allTiles.size() < this.size();
+                        try {
+                            newInfo.hasLoadingTiles = allTiles.size() < this.size();
+                        } catch (ArithmeticException arithmeticException) {
+                            Logging.trace(arithmeticException);
+                            newInfo.hasLoadingTiles = false;
+                        }
                         newInfo.hasAllLoadedTiles = true;
                         for (Tile t : allTiles) {
@@ -1450,5 +1463,16 @@
         @Override
         public String toString() {
-            return getClass().getName() + ": zoom: " + zoom + " X(" + minX + ", " + maxX + ") Y(" + minY + ", " + maxY + ") size: " + size();
+            int size;
+            try {
+                size = size();
+            } catch (ArithmeticException arithmeticException) {
+                Logging.trace(arithmeticException);
+                size = Integer.MIN_VALUE;
+            }
+            return getClass().getName()
+                    + ": zoom: " + zoom
+                    + " X(" + minX + ", " + maxX
+                    + ") Y(" + minY + ", " + maxY
+                    + ") size: " + (size >= 0 ? size : "Integer Overflow");
         }
     }
@@ -1473,5 +1497,6 @@
         if (zoom == 0)
             return new TileSet();
-        TileXY t1, t2;
+        TileXY t1;
+        TileXY t2;
         IProjected topLeftUnshifted = coordinateConverter.shiftDisplayToServer(bounds.getMin());
         IProjected botRightUnshifted = coordinateConverter.shiftDisplayToServer(bounds.getMax());
@@ -1496,5 +1521,6 @@
     private class DeepTileSet {
         private final ProjectionBounds bounds;
-        private final int minZoom, maxZoom;
+        private final int minZoom;
+        private final int maxZoom;
         private final TileSet[] tileSets;
 
@@ -1993,5 +2019,5 @@
     public synchronized void destroy() {
         super.destroy();
-        MapView.removeZoomChangeListener(this);
+        NavigatableComponent.removeZoomChangeListener(this);
         adjustAction.destroy();
         if (tileLoader instanceof TMSCachedTileLoader) {
@@ -2053,5 +2079,5 @@
         public void detachFromMapView(MapViewEvent event) {
             event.getMapView().removeMouseListener(adapter);
-            MapView.removeZoomChangeListener(AbstractTileSourceLayer.this);
+            NavigatableComponent.removeZoomChangeListener(AbstractTileSourceLayer.this);
             super.detachFromMapView(event);
             if (memory != null) {
