Changeset 19180 in josm


Ignore:
Timestamp:
2024-08-12T17:35:51+02:00 (6 months ago)
Author:
taylor.smock
Message:

Fix some coverity issues

Location:
trunk/src/org/openstreetmap/josm
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/imagery/CachedAttributionBingAerialTileSource.java

    r19145 r19180  
    1010import java.nio.charset.StandardCharsets;
    1111import java.util.List;
     12import java.util.Objects;
    1213import java.util.Timer;
    1314import java.util.TimerTask;
    1415import java.util.concurrent.Callable;
    15 import java.util.concurrent.atomic.AtomicBoolean;
     16import java.util.concurrent.CountDownLatch;
     17import java.util.concurrent.TimeUnit;
    1618import java.util.concurrent.atomic.AtomicReference;
    1719
     
    8991    protected Callable<List<Attribution>> getAttributionLoaderCallable() {
    9092        final AtomicReference<List<Attribution>> attributions = new AtomicReference<>();
    91         final AtomicBoolean finished = new AtomicBoolean();
     93        final CountDownLatch finished = new CountDownLatch(1);
    9294        return () -> {
    9395            final PleaseWaitProgressMonitor monitor = new PleaseWaitProgressMonitor();
     
    9597            final Timer timer = new Timer(Thread.currentThread().getName() + "-timer", true);
    9698            timer.schedule(new AttributionTimerTask(monitor, timer, 1, attributions, finished), 0);
    97             synchronized (finished) {
    98                 while (!finished.get() && !monitor.isCanceled()) {
    99                     finished.wait(1000);
     99            try {
     100                while (!monitor.isCanceled() && !finished.await(1, TimeUnit.SECONDS)) {
     101                    // Do nothing; we are waiting on the CountDownLatch to hit zero.
    100102                }
     103            } finally {
     104                monitor.finishTask();
     105                monitor.close();
    101106            }
    102             monitor.finishTask();
    103             monitor.close();
    104107            return attributions.get();
    105108        };
     
    114117        private final int waitTimeSec;
    115118        private final AtomicReference<List<Attribution>> attributions;
    116         private final AtomicBoolean finished;
     119        private final CountDownLatch finished;
    117120
    118121        /**
     
    125128         */
    126129        AttributionTimerTask(ProgressMonitor monitor, Timer timer, int waitTimeSec,
    127                              AtomicReference<List<Attribution>> attributions, AtomicBoolean finished) {
     130                             AtomicReference<List<Attribution>> attributions, CountDownLatch finished) {
    128131            this.monitor = monitor;
    129132            this.timer = timer;
     
    138141            try {
    139142                String xml = attributionLoader.updateIfRequiredString();
     143                Objects.requireNonNull(xml);
    140144                List<Attribution> ret;
    141145                try (StringReader sr = new StringReader(xml)) {
     
    147151                }
    148152                this.attributions.set(ret);
    149                 this.finished.set(true);
     153                this.finished.countDown();
    150154            } catch (IOException ex) {
    151155                final String message = tr("Could not connect to Bing API. Will retry in {0} seconds.", waitTimeSec);
    152156                Logging.log(Logging.LEVEL_WARN, message, ex);
    153157                if (this.monitor.isCanceled()) {
    154                     this.finished.set(true);
     158                    this.finished.countDown();
    155159                    return;
    156160                }
     
    160164                this.timer.schedule(new AttributionTimerTask(this.monitor, this.timer, newWaitTimeSec, this.attributions, this.finished),
    161165                        newWaitTimeSec * 1000L);
    162             } finally {
    163                 synchronized (this.finished) {
    164                     this.finished.notifyAll();
    165                 }
    166166            }
    167167        }
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/StyledTiledMapRenderer.java

    r19176 r19180  
    251251        temporaryView.zoomTo(bounds.getCenter().getEastNorth(ProjectionRegistry.getProjection()), mapState.getScale());
    252252        BufferedImage bufferedImage = Optional.ofNullable(nc.getGraphicsConfiguration())
    253                 .map(gc -> gc.createCompatibleImage(tileSize * xCount + xCount, tileSize * yCount + xCount, Transparency.TRANSLUCENT))
    254                 .orElseGet(() -> new BufferedImage(tileSize * xCount + xCount, tileSize * yCount + xCount, BufferedImage.TYPE_INT_ARGB));
     253                .map(gc -> gc.createCompatibleImage(tileSize * xCount + xCount, tileSize * yCount + yCount, Transparency.TRANSLUCENT))
     254                .orElseGet(() -> new BufferedImage(tileSize * xCount + xCount, tileSize * yCount + yCount, BufferedImage.TYPE_INT_ARGB));
    255255        Graphics2D g2d = bufferedImage.createGraphics();
    256256        try {
     
    335335         * @param tImage The tile image for this job
    336336         */
    337         private synchronized void cacheTile(BufferedImage tImage) {
     337        private void cacheTile(BufferedImage tImage) {
    338338            cache.put(tile, new ImageCache(tImage, null, false));
    339339            done = true;
  • trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java

    r19176 r19180  
    13421342        // 256 is the "target" size, (TODO check HiDPI!)
    13431343        final int targetSize = Config.getPref().getInt("mappaint.fast_render.tile_size", 256);
     1344        CheckParameterUtil.ensureThat(targetSize > 0, "mappaint.fast_render.tile_size should be > 0 (default 256)");
    13441345        final double topResolution = 2 * Math.PI * OsmMercator.EARTH_RADIUS / targetSize;
    13451346        int zoom;
Note: See TracChangeset for help on using the changeset viewer.