Changeset 8357 in josm for trunk


Ignore:
Timestamp:
2015-05-15T23:49:31+02:00 (9 years ago)
Author:
Don-vip
Message:

fix some Findbugs violations

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

Legend:

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

    r8342 r8357  
    337337     * Class that represent a line
    338338     */
    339     private class Line {
     339    private static class Line {
    340340
    341341        /**
  • trunk/src/org/openstreetmap/josm/actions/JoinAreasAction.java

    r8342 r8357  
    765765        List<WayInPolygon> result = new ArrayList<>();
    766766
    767         //prepare prev and next maps
     767        //prepare next map
    768768        Map<Way, Way> nextWayMap = new HashMap<>();
    769         Map<Way, Way> prevWayMap = new HashMap<>();
    770769
    771770        for (int pos = 0; pos < parts.size(); pos ++) {
     
    775774
    776775            nextWayMap.put(parts.get(pos), parts.get((pos + 1) % parts.size()));
    777             prevWayMap.put(parts.get(pos), parts.get((pos + parts.size() - 1) % parts.size()));
    778776        }
    779777
  • trunk/src/org/openstreetmap/josm/actions/RestartAction.java

    r8356 r8357  
    114114                String[] mainCommand = System.getProperty("sun.java.command").split(" ");
    115115                // look for a .jar in all chunks to support paths with spaces (fix #9077)
    116                 String jarPath = mainCommand[0];
    117                 for (int i = 1; i < mainCommand.length && !jarPath.endsWith(".jar"); i++) {
    118                     jarPath += " " + mainCommand[i];
    119                 }
     116                StringBuilder sb = new StringBuilder(mainCommand[0]);
     117                for (int i = 1; i < mainCommand.length && !mainCommand[i-1].endsWith(".jar"); i++) {
     118                    sb.append(" ").append(mainCommand[i]);
     119                }
     120                String jarPath = sb.toString();
    120121                // program main is a jar
    121122                if (jarPath.endsWith(".jar")) {
  • trunk/src/org/openstreetmap/josm/data/AutosaveTask.java

    r8308 r8357  
    197197                Main.warn(tr("Unable to delete old backup file {0}", oldFile.getAbsolutePath()));
    198198            } else {
    199                 getPidFile(oldFile).delete();
     199                File pidFile = getPidFile(oldFile);
     200                if (!pidFile.delete()) {
     201                    Main.warn(tr("Unable to delete old backup file {0}", pidFile.getAbsolutePath()));
     202                }
    200203            }
    201204        }
  • trunk/src/org/openstreetmap/josm/data/Preferences.java

    r8344 r8357  
    815815        File tmpFile = new File(prefFile + "_tmp");
    816816        Utils.copyFile(tmpFile, prefFile);
    817         tmpFile.delete();
     817        if (!tmpFile.delete()) {
     818            Main.warn(tr("Unable to delete temporary file {0}", tmpFile.getAbsolutePath()));
     819        }
    818820
    819821        setCorrectPermissions(prefFile);
     
    822824
    823825    private void setCorrectPermissions(File file) {
    824         file.setReadable(false, false);
    825         file.setWritable(false, false);
    826         file.setExecutable(false, false);
    827         file.setReadable(true, true);
    828         file.setWritable(true, true);
     826        if (!file.setReadable(false, false) && Main.isDebugEnabled()) {
     827            Main.debug(tr("Unable to set file non-readable {0}", file.getAbsolutePath()));
     828        }
     829        if (!file.setWritable(false, false) && Main.isDebugEnabled()) {
     830            Main.debug(tr("Unable to set file non-writable {0}", file.getAbsolutePath()));
     831        }
     832        if (!file.setExecutable(false, false) && Main.isDebugEnabled()) {
     833            Main.debug(tr("Unable to set file non-executable {0}", file.getAbsolutePath()));
     834        }
     835        if (!file.setReadable(true, true) && Main.isDebugEnabled()) {
     836            Main.debug(tr("Unable to set file readable {0}", file.getAbsolutePath()));
     837        }
     838        if (!file.setWritable(true, true) && Main.isDebugEnabled()) {
     839            Main.debug(tr("Unable to set file writable {0}", file.getAbsolutePath()));
     840        }
    829841    }
    830842
  • trunk/src/org/openstreetmap/josm/data/cache/JCSCacheManager.java

    r8345 r8357  
    5656
    5757        File cacheDirLockPath = new File(cacheDir, ".lock");
    58         if (!cacheDirLockPath.exists())
    59             cacheDirLockPath.createNewFile();
     58        if (!cacheDirLockPath.exists() && !cacheDirLockPath.createNewFile()) {
     59            log.log(Level.WARNING, "Cannot create cache dir lock file");
     60        }
    6061        cacheDirLock = new FileOutputStream(cacheDirLockPath).getChannel().tryLock();
    6162
  • trunk/src/org/openstreetmap/josm/data/coor/CachedLatLon.java

    r8308 r8357  
    99 *
    1010 * This class is convenient to use, but has relatively high memory costs.
    11  * It keeps a pointer to the last known projection in order to detect projection
    12  * changes.
     11 * It keeps a pointer to the last known projection in order to detect projection changes.
    1312 *
    1413 * Node and WayPoint have another, optimized, cache for projected coordinates.
    1514 */
    1615public class CachedLatLon extends LatLon {
     16
     17    private static final long serialVersionUID = 1L;
     18
    1719    private EastNorth eastNorth;
    1820    private transient Projection proj;
    1921
     22    /**
     23     * Constructs a new {@code CachedLatLon}.
     24     * @param lat latitude
     25     * @param lon longitude
     26     */
    2027    public CachedLatLon(double lat, double lon) {
    2128        super(lat, lon);
    2229    }
    2330
     31    /**
     32     * Constructs a new {@code CachedLatLon}.
     33     * @param coor lat/lon
     34     */
    2435    public CachedLatLon(LatLon coor) {
    2536        super(coor.lat(), coor.lon());
     
    2738    }
    2839
     40    /**
     41     * Constructs a new {@code CachedLatLon}.
     42     * @param eastNorth easting/northing
     43     */
    2944    public CachedLatLon(EastNorth eastNorth) {
    3045        super(Main.getProjection().eastNorth2latlon(eastNorth));
     
    3954     */
    4055    public final EastNorth getEastNorth() {
    41         if(proj != Main.getProjection())
    42         {
     56        if (proj != Main.getProjection()) {
    4357            proj = Main.getProjection();
    4458            eastNorth = proj.latlon2eastNorth(this);
     
    4660        return eastNorth;
    4761    }
    48     @Override public String toString() {
     62
     63    @Override
     64    public String toString() {
    4965        return "CachedLatLon[lat="+lat()+",lon="+lon()+"]";
    5066    }
    51 
    52     // Only for Node.get3892DebugInfo()
    53     public Projection getProjection() {
    54         return proj;
    55     }
    5667}
  • trunk/src/org/openstreetmap/josm/data/imagery/WmsCache.java

    r8345 r8357  
    112112    public WmsCache(String url, int tileSize) {
    113113        File globalCacheDir = new File(cacheDirPath());
    114         globalCacheDir.mkdirs();
     114        if (!globalCacheDir.mkdirs()) {
     115            Main.warn("Unable to create global cache directory: "+globalCacheDir.getAbsolutePath());
     116        }
    115117        cacheDir = new File(globalCacheDir, getCacheDirectory(url));
    116118        cacheDir.mkdirs();
     
    230232                if (files != null) {
    231233                    for (File file: files) {
    232                         if (!referencedFiles.contains(file.getName())) {
    233                             file.delete();
     234                        if (!referencedFiles.contains(file.getName()) && !file.delete()) {
     235                            Main.warn("Unable to delete file: "+file.getAbsolutePath());
    234236                        }
    235237                    }
     
    530532        }
    531533
    532         imageFile.getParentFile().mkdirs();
     534        if (!imageFile.getParentFile().mkdirs()) {
     535            Main.warn("Unable to create parent directory: "+imageFile.getParentFile().getAbsolutePath());
     536        }
    533537
    534538        if (img != null) {
     
    555559                    }
    556560                    totalFileSize -= size;
    557                     file.delete();
     561                    if (!file.delete()) {
     562                        Main.warn("Unable to delete file: "+file.getAbsolutePath());
     563                    }
    558564                    it.remove();
    559565                }
Note: See TracChangeset for help on using the changeset viewer.