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


Ignore:
Timestamp:
2023-12-27T19:52:41+01:00 (6 months ago)
Author:
taylor.smock
Message:

Fix #23367: Don't try to load too many tiles

In this case, we are catching an ArithmeticException when an integer overflow occurs.

Additionally, fix some lint issues and update some dependencies:

  • org.openstreetmap.jmapviewer:jmapviewer: 2.18 -> 2.19
  • ch.poole:OpeningHoursParser: 0.27.1 -> 0.28.0
  • nl.jqno.equalsverifier:equalsverifier: 3.15.4 -> 3.15.5
  • com.google.errorprone:error_prone_core: 2.23.0 -> 2.24.0
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/layer/AbstractTileSourceLayer.java

    r18871 r18926  
    22package org.openstreetmap.josm.gui.layer;
    33
     4import static org.openstreetmap.josm.tools.I18n.marktr;
    45import static org.openstreetmap.josm.tools.I18n.tr;
    56
     
    1011import java.awt.Graphics;
    1112import java.awt.Graphics2D;
     13import java.awt.GridBagConstraints;
    1214import java.awt.GridBagLayout;
    1315import java.awt.Image;
     
    179181
    180182    private static final BooleanProperty POPUP_MENU_ENABLED = new BooleanProperty(PREFERENCE_PREFIX + ".popupmenu", true);
     183    private static final String ERROR_STRING = marktr("Error");
    181184
    182185    /*
     
    343346            panel.add(new JLabel(entry.get(0) + ':'), GBC.std());
    344347            panel.add(GBC.glue(5, 0), GBC.std());
    345             panel.add(createTextField(entry.get(1)), GBC.eol().fill(GBC.HORIZONTAL));
     348            panel.add(createTextField(entry.get(1)), GBC.eol().fill(GridBagConstraints.HORIZONTAL));
    346349        }
    347350        return panel;
     
    469472                content.add(Arrays.asList(tr("Loaded"), tr(Boolean.toString(tile.isLoaded()))));
    470473                content.add(Arrays.asList(tr("Loading"), tr(Boolean.toString(tile.isLoading()))));
    471                 content.add(Arrays.asList(tr("Error"), tr(Boolean.toString(tile.hasError()))));
     474                content.add(Arrays.asList(tr(ERROR_STRING), tr(Boolean.toString(tile.hasError()))));
    472475                for (List<String> entry: content) {
    473476                    panel.add(new JLabel(entry.get(0) + ':'), GBC.std());
    474477                    panel.add(GBC.glue(5, 0), GBC.std());
    475                     panel.add(layer.createTextField(entry.get(1)), GBC.eol().fill(GBC.HORIZONTAL));
     478                    panel.add(layer.createTextField(entry.get(1)), GBC.eol().fill(GridBagConstraints.HORIZONTAL));
    476479                }
    477480
     
    483486                        value = Instant.ofEpochMilli(Long.parseLong(value)).toString();
    484487                    }
    485                     panel.add(layer.createTextField(value), GBC.eol().fill(GBC.HORIZONTAL));
     488                    panel.add(layer.createTextField(value), GBC.eol().fill(GridBagConstraints.HORIZONTAL));
    486489
    487490                }
     
    559562
    560563        event.getMapView().addMouseListener(adapter);
    561         MapView.addZoomChangeListener(this);
     564        NavigatableComponent.addZoomChangeListener(this);
    562565
    563566        if (this instanceof NativeScaleLayer && Boolean.TRUE.equals(NavigatableComponent.PROP_ZOOM_SCALE_FOLLOW_NATIVE_RES_AT_LOAD.get())) {
     
    12061209                    Logging.debug(e);
    12071210                }
    1208                 if (!errorMessage.startsWith("Error") && !errorMessage.startsWith(tr("Error"))) {
    1209                     errorMessage = tr("Error") + ": " + errorMessage;
     1211                if (!errorMessage.startsWith(ERROR_STRING) && !errorMessage.startsWith(tr(ERROR_STRING))) {
     1212                    errorMessage = tr(ERROR_STRING) + ": " + errorMessage;
    12101213                }
    12111214                myDrawString(g, errorMessage, x + 2, texty);
     
    12641267
    12651268        private boolean tooLarge() {
    1266             return tileCache == null || size() > tileCache.getCacheSize();
     1269            try {
     1270                return tileCache == null || size() > tileCache.getCacheSize();
     1271            } catch (ArithmeticException arithmeticException) {
     1272                Logging.trace(arithmeticException);
     1273                return true;
     1274            }
    12671275        }
    12681276
     
    14241432                        List<Tile> allTiles = this.allExistingTiles();
    14251433                        TileSetInfo newInfo = new TileSetInfo();
    1426                         newInfo.hasLoadingTiles = allTiles.size() < this.size();
     1434                        try {
     1435                            newInfo.hasLoadingTiles = allTiles.size() < this.size();
     1436                        } catch (ArithmeticException arithmeticException) {
     1437                            Logging.trace(arithmeticException);
     1438                            newInfo.hasLoadingTiles = false;
     1439                        }
    14271440                        newInfo.hasAllLoadedTiles = true;
    14281441                        for (Tile t : allTiles) {
     
    14501463        @Override
    14511464        public String toString() {
    1452             return getClass().getName() + ": zoom: " + zoom + " X(" + minX + ", " + maxX + ") Y(" + minY + ", " + maxY + ") size: " + size();
     1465            int size;
     1466            try {
     1467                size = size();
     1468            } catch (ArithmeticException arithmeticException) {
     1469                Logging.trace(arithmeticException);
     1470                size = Integer.MIN_VALUE;
     1471            }
     1472            return getClass().getName()
     1473                    + ": zoom: " + zoom
     1474                    + " X(" + minX + ", " + maxX
     1475                    + ") Y(" + minY + ", " + maxY
     1476                    + ") size: " + (size >= 0 ? size : "Integer Overflow");
    14531477        }
    14541478    }
     
    14731497        if (zoom == 0)
    14741498            return new TileSet();
    1475         TileXY t1, t2;
     1499        TileXY t1;
     1500        TileXY t2;
    14761501        IProjected topLeftUnshifted = coordinateConverter.shiftDisplayToServer(bounds.getMin());
    14771502        IProjected botRightUnshifted = coordinateConverter.shiftDisplayToServer(bounds.getMax());
     
    14961521    private class DeepTileSet {
    14971522        private final ProjectionBounds bounds;
    1498         private final int minZoom, maxZoom;
     1523        private final int minZoom;
     1524        private final int maxZoom;
    14991525        private final TileSet[] tileSets;
    15001526
     
    19932019    public synchronized void destroy() {
    19942020        super.destroy();
    1995         MapView.removeZoomChangeListener(this);
     2021        NavigatableComponent.removeZoomChangeListener(this);
    19962022        adjustAction.destroy();
    19972023        if (tileLoader instanceof TMSCachedTileLoader) {
     
    20532079        public void detachFromMapView(MapViewEvent event) {
    20542080            event.getMapView().removeMouseListener(adapter);
    2055             MapView.removeZoomChangeListener(AbstractTileSourceLayer.this);
     2081            NavigatableComponent.removeZoomChangeListener(AbstractTileSourceLayer.this);
    20562082            super.detachFromMapView(event);
    20572083            if (memory != null) {
Note: See TracChangeset for help on using the changeset viewer.