Changeset 9645 in josm for trunk/src/org


Ignore:
Timestamp:
2016-01-27T02:01:55+01:00 (8 years ago)
Author:
Don-vip
Message:

fix findbugs issue RV_RETURN_VALUE_IGNORED_BAD_PRACTICE for java.io.File.mkdirs

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/validation/OsmValidator.java

    r9246 r9645  
    166166            File pathDir = new File(getValidatorDir());
    167167            if (!pathDir.exists()) {
    168                 pathDir.mkdirs();
     168                Utils.mkDirs(pathDir);
    169169            }
    170170        } catch (Exception e) {
  • trunk/src/org/openstreetmap/josm/gui/io/DownloadFileTask.java

    r9309 r9645  
    9696                File newDir = file.getParentFile();
    9797                if (!newDir.exists()) {
    98                     newDir.mkdirs();
     98                    Utils.mkDirs(newDir);
    9999                }
    100100            }
     
    184184                File newFile = new File(dir, ze.getName());
    185185                if (ze.isDirectory()) {
    186                     newFile.mkdirs();
     186                    Utils.mkDirs(newFile);
    187187                } else try (InputStream is = zf.getInputStream(ze)) {
    188188                    Files.copy(is, newFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
  • trunk/src/org/openstreetmap/josm/io/CachedFile.java

    r9545 r9645  
    427427        File destDirFile = new File(destDir);
    428428        if (!destDirFile.exists()) {
    429             destDirFile.mkdirs();
     429            Utils.mkDirs(destDirFile);
    430430        }
    431431
  • trunk/src/org/openstreetmap/josm/plugins/Plugin.java

    r9280 r9645  
    118118        File pluginDir = new File(pluginDirName);
    119119        if (!pluginDir.exists()) {
    120             pluginDir.mkdirs();
     120            Utils.mkDirs(pluginDir);
    121121        }
    122122        try (InputStream in = getClass().getResourceAsStream(from)) {
  • trunk/src/org/openstreetmap/josm/tools/PlatformHookOsx.java

    r9296 r9645  
    364364                if (!newPref.exists()) {
    365365                    try {
    366                         Main.pref.getPreferencesDirectory().mkdirs();
     366                        Utils.mkDirs(Main.pref.getPreferencesDirectory());
    367367                        Main.info("Copying old preferences file to new location");
    368368                        Utils.copyFile(oldPref, newPref);
  • trunk/src/org/openstreetmap/josm/tools/Utils.java

    r9477 r9645  
    460460     * Deletes a file and log a default warning if the deletion fails.
    461461     * @param file file to delete
    462      * and must contain a single parameter <code>{0}</code> for the file path
    463462     * @return {@code true} if and only if the file is successfully deleted; {@code false} otherwise
    464463     * @since 9296
     
    480479        if (!result) {
    481480            Main.warn(tr(warnMsg, file.getPath()));
     481        }
     482        return result;
     483    }
     484
     485    /**
     486     * Creates a directory and log a default warning if the creation fails.
     487     * @param dir directory to create
     488     * @return {@code true} if and only if the directory is successfully created; {@code false} otherwise
     489     * @since 9645
     490     */
     491    public static boolean mkDirs(File dir) {
     492        return mkDirs(dir, marktr("Unable to create directory {0}"));
     493    }
     494
     495    /**
     496     * Creates a directory and log a configurable warning if the creation fails.
     497     * @param dir directory to create
     498     * @param warnMsg warning message. It will be translated with {@code tr()}
     499     * and must contain a single parameter <code>{0}</code> for the directory path
     500     * @return {@code true} if and only if the directory is successfully created; {@code false} otherwise
     501     * @since 9645
     502     */
     503    public static boolean mkDirs(File dir, String warnMsg) {
     504        boolean result = dir.mkdirs();
     505        if (!result) {
     506            Main.warn(tr(warnMsg, dir.getPath()));
    482507        }
    483508        return result;
Note: See TracChangeset for help on using the changeset viewer.