Ignore:
Timestamp:
2023-02-16T16:01:49+01:00 (20 months ago)
Author:
taylor.smock
Message:

Fix several coverity issues

CID-1504572: Synchronization on java.util.concurrent objects

The lock wasn't necessary after moving from AtomicBoolean to
CountDownLatch

CID-1504570: Dereference null value -- the default getApiUrl return was null
CID-1504570: Explicit null dereferenced

Consumer<IOAuthToken> to Consumer<Optional<IOAuthToken>>

CID-1476014, CID-1476013, CID-1476011: Resource leak

These resource leaks are unlikely to happen outside of plugin code,
and are all related to StringSelection#getTransferData, which may
return a Closeable object, but is unlikely to be the Transferable
for any of the affected classes.


This also fixes some recently introduced SonarLint issues. It also suppresses
squid:S100 ("Method names should comply with a naming convention") for the MapCSS
Functions class, since the convention for that method names in that class is
^[a-zA-Z][a-zA-Z0-9_]*$

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/datatransfer/importers/FilePaster.java

    r17556 r18665  
    44import java.awt.datatransfer.DataFlavor;
    55import java.awt.datatransfer.UnsupportedFlavorException;
     6import java.io.Closeable;
    67import java.io.File;
    78import java.io.IOException;
     
    1516import org.openstreetmap.josm.gui.io.importexport.Options;
    1617import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     18import org.openstreetmap.josm.tools.Utils;
    1719
    1820/**
     
    3234    public boolean importData(TransferSupport support, OsmDataLayer layer, EastNorth pasteAt)
    3335            throws UnsupportedFlavorException, IOException {
    34         @SuppressWarnings("unchecked")
    35         List<File> files = (List<File>) support.getTransferable().getTransferData(df);
    36         OpenFileAction.OpenFileTask task = new OpenFileAction.OpenFileTask(files, null);
    37         task.setOptions(Options.RECORD_HISTORY);
    38         MainApplication.worker.submit(task);
    39         return true;
     36        final Object data = support.getTransferable().getTransferData(df);
     37        if (data instanceof List) {
     38            @SuppressWarnings("unchecked")
     39            List<File> files = (List<File>) data;
     40            OpenFileAction.OpenFileTask task = new OpenFileAction.OpenFileTask(files, null);
     41            task.setOptions(Options.RECORD_HISTORY);
     42            MainApplication.worker.submit(task);
     43            return true;
     44        }
     45        // We should never hit this code -- Coverity thinks that it is possible for this to be called with a
     46        // StringSelection transferable, which is not currently possible with our code. It *could* be done from
     47        // a plugin though.
     48        if (data instanceof Closeable) {
     49            Utils.close((Closeable) data);
     50        }
     51        throw new UnsupportedFlavorException(df);
    4052    }
    4153}
Note: See TracChangeset for help on using the changeset viewer.