Changeset 18472 in josm


Ignore:
Timestamp:
2022-06-08T17:33:09+02:00 (2 years ago)
Author:
taylor.smock
Message:

Fix some coverity warnings

  • CID 1489777: FB.RV_RETURN_VALUE_IGNORED_BAD_PRACTICE Fixed by using Files.deleteIfExists instead of File.delete. We do catch the security exception and print a message for the user.
  • CID 1489773: FORWARD_NULL Fixed by synchronizing around the potential null object. Shouldn't be too expensive, as it is mostly UI loop.
Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/SessionSaveAction.java

    r18466 r18472  
    1414import java.io.IOException;
    1515import java.lang.ref.WeakReference;
     16import java.nio.file.Files;
    1617import java.util.ArrayList;
    1718import java.util.Arrays;
     
    5354import org.openstreetmap.josm.gui.layer.LayerManager.LayerOrderChangeEvent;
    5455import org.openstreetmap.josm.gui.layer.LayerManager.LayerRemoveEvent;
     56import org.openstreetmap.josm.gui.util.GuiHelper;
    5557import org.openstreetmap.josm.gui.util.WindowGeometry;
    5658import org.openstreetmap.josm.gui.widgets.AbstractFileChooser;
     
    252254            if (removeFileOnSuccess != null) {
    253255                PreferencesUtils.removeFromList(Config.getPref(), "file-open.history", removeFileOnSuccess.getCanonicalPath());
    254                 removeFileOnSuccess.delete();
     256                Files.deleteIfExists(removeFileOnSuccess.toPath());
    255257                removeFileOnSuccess = null;
    256258            }
    257259            showSavedNotification(savingNotification, sessionFile.getName());
     260        } catch (SecurityException ex) {
     261            Logging.error(ex);
     262            if (removeFileOnSuccess != null) {
     263                final String path = removeFileOnSuccess.getPath();
     264                GuiHelper.runInEDT(() -> {
     265                    Notification notification = new Notification(tr("Could not delete file: {0}\r{1}", path, ex.getMessage()));
     266                    notification.setIcon(JOptionPane.WARNING_MESSAGE);
     267                    notification.show();
     268                });
     269            } else {
     270                // We should never hit this, unless something changes in the try block.
     271                throw new JosmRuntimeException(ex);
     272            }
    258273        } catch (IOException ex) {
    259274            Logging.error(ex);
     
    273288    /**
    274289     * Sets the current session file. Asks the user if necessary
    275      * @param saveAs alwas ask the user
     290     * @param saveAs always ask the user
    276291     * @param zipRequired zip
    277292     * @return if the user was asked
  • trunk/src/org/openstreetmap/josm/gui/io/UploadDialog.java

    r18467 r18472  
    9797
    9898    private transient DataSet dataSet;
    99     private ChangeListener changesetTagListener;
     99    private transient ChangeListener changesetTagListener;
    100100
    101101    /**
     
    372372     * the changeset tags.
    373373     */
    374     public void setChangesetTagsModifiedProgramatically() {
     374    public synchronized void setChangesetTagsModifiedProgramatically() {
    375375        final Color originalColor = this.tpConfigPanels.getBackgroundAt(1);
    376376        this.tpConfigPanels.setBackgroundAt(1, WARNING_BACKGROUND);
     
    383383                tpConfigPanels.setBackgroundAt(1, originalColor);
    384384                tpConfigPanels.setIconAt(1, ImageProvider.get("apply"));
    385                 this.tpConfigPanels.removeChangeListener(this.changesetTagListener);
    386                 changesetTagListener = null;
     385                synchronized (this) {
     386                    this.tpConfigPanels.removeChangeListener(this.changesetTagListener);
     387                    changesetTagListener = null;
     388                }
    387389            }
    388390        };
     
    575577        if (e.getKey() != null
    576578                && e.getSource() != getClass()
    577                 && e.getSource() != BasicUploadSettingsPanel.class) {
    578             switch (e.getKey()) {
    579                 case "osm-server.url":
    580                     osmServerUrlChanged(e.getNewValue());
    581                     break;
    582                 default:
    583                     return;
    584             }
     579                && e.getSource() != BasicUploadSettingsPanel.class
     580                && "osm-server.url".equals(e.getKey())) {
     581            osmServerUrlChanged(e.getNewValue());
    585582        }
    586583    }
     
    643640        setUploadedPrimitives(null);
    644641        dataSet = null;
    645         if (this.changesetTagListener != null) {
    646             this.changesetTagListener.stateChanged(null);
    647             this.tpConfigPanels.removeChangeListener(this.changesetTagListener);
    648             this.changesetTagListener = null;
     642        synchronized (this) {
     643            if (this.changesetTagListener != null) {
     644                this.changesetTagListener.stateChanged(null);
     645                this.tpConfigPanels.removeChangeListener(this.changesetTagListener);
     646                this.changesetTagListener = null;
     647            }
    649648        }
    650649    }
Note: See TracChangeset for help on using the changeset viewer.