Ignore:
Timestamp:
2016-01-04T01:06:23+01:00 (4 years ago)
Author:
Don-vip
Message:

fix #12249 - Fix Findbugs warnings "Exceptional return value of java.io.File.delete() ignored"

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/PlatformHookOsx.java

    r8923 r9296  
    22package org.openstreetmap.josm.tools;
    33
     4import static org.openstreetmap.josm.tools.I18n.marktr;
    45import static org.openstreetmap.josm.tools.I18n.tr;
    56
     
    366367                        Main.info("Copying old preferences file to new location");
    367368                        Utils.copyFile(oldPref, newPref);
    368                         if (!oldPref.delete()) {
    369                             Main.warn("Unable to delete old preferences file: "+oldPref.getPath());
    370                         }
     369                        Utils.deleteFile(oldPref, marktr("Unable to delete old preferences file {0}"));
    371370                    } catch (IOException e) {
    372371                        Main.error(e);
  • trunk/src/org/openstreetmap/josm/tools/PlatformHookWindows.java

    r9073 r9296  
    190190    public boolean rename(File from, File to) {
    191191        if (to.exists())
    192             to.delete();
     192            Utils.deleteFile(to);
    193193        return from.renameTo(to);
    194194    }
  • trunk/src/org/openstreetmap/josm/tools/Utils.java

    r9280 r9296  
    22package org.openstreetmap.josm.tools;
    33
     4import static org.openstreetmap.josm.tools.I18n.marktr;
    45import static org.openstreetmap.josm.tools.I18n.tr;
    56import static org.openstreetmap.josm.tools.I18n.trn;
     
    446447                    if (file.isDirectory()) {
    447448                        deleteDirectory(file);
    448                     } else if (!file.delete()) {
    449                         Main.warn("Unable to delete file: "+file.getPath());
     449                    } else {
     450                        deleteFile(file);
    450451                    }
    451452                }
     
    453454        }
    454455        return path.delete();
     456    }
     457
     458    /**
     459     * Deletes a file and log a default warning if the deletion fails.
     460     * @param file file to delete
     461     * and must contain a single parameter <code>{0}</code> for the file path
     462     * @return {@code true} if and only if the file is successfully deleted; {@code false} otherwise
     463     * @since XXXX
     464     */
     465    public static boolean deleteFile(File file) {
     466        return deleteFile(file, marktr("Unable to delete file {0}"));
     467    }
     468
     469    /**
     470     * Deletes a file and log a configurable warning if the deletion fails.
     471     * @param file file to delete
     472     * @param warnMsg warning message. It will be translated with {@code tr()}
     473     * and must contain a single parameter <code>{0}</code> for the file path
     474     * @return {@code true} if and only if the file is successfully deleted; {@code false} otherwise
     475     * @since XXXX
     476     */
     477    public static boolean deleteFile(File file, String warnMsg) {
     478        boolean result = file.delete();
     479        if (!result) {
     480            Main.warn(tr(warnMsg, file.getPath()));
     481        }
     482        return result;
    455483    }
    456484
Note: See TracChangeset for help on using the changeset viewer.