Ignore:
Timestamp:
2018-04-19T22:34:52+02:00 (2 years ago)
Author:
Don-vip
Message:

fix #16204 - allow to create a new layer, draw, drag, open a few windows. Nothing more to hope in sandbox mode. At least JOSM is now more robust than ever.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/cache/JCSCacheManager.java

    r13647 r13649  
    108108        File cacheDir = new File(Config.getDirs().getCacheDirectory(true), "jcs");
    109109
    110         if (!cacheDir.exists() && !cacheDir.mkdirs()) {
    111             Logging.warn("Cache directory " + cacheDir.toString() + " does not exists and could not create it");
    112         } else {
    113             File cacheDirLockPath = new File(cacheDir, ".lock");
    114             try {
    115                 if (!cacheDirLockPath.exists() && !cacheDirLockPath.createNewFile()) {
    116                     Logging.warn("Cannot create cache dir lock file");
    117                 }
    118                 cacheDirLock = FileChannel.open(cacheDirLockPath.toPath(), StandardOpenOption.WRITE).tryLock();
    119 
    120                 if (cacheDirLock == null)
    121                     Logging.warn("Cannot lock cache directory. Will not use disk cache");
    122             } catch (IOException e) {
    123                 Logging.warn("Cannot create cache dir \"" + cacheDirLockPath.toString() + "\" lock file: " + e.toString());
    124                 Logging.warn("Will not use disk cache");
     110        try {
     111            if (!cacheDir.exists() && !cacheDir.mkdirs()) {
     112                Logging.warn("Cache directory " + cacheDir.toString() + " does not exists and could not create it");
     113            } else {
     114                File cacheDirLockPath = new File(cacheDir, ".lock");
     115                try {
     116                    if (!cacheDirLockPath.exists() && !cacheDirLockPath.createNewFile()) {
     117                        Logging.warn("Cannot create cache dir lock file");
     118                    }
     119                    cacheDirLock = FileChannel.open(cacheDirLockPath.toPath(), StandardOpenOption.WRITE).tryLock();
     120
     121                    if (cacheDirLock == null)
     122                        Logging.warn("Cannot lock cache directory. Will not use disk cache");
     123                } catch (IOException e) {
     124                    Logging.warn("Cannot create cache dir \"" + cacheDirLockPath.toString() + "\" lock file: " + e.toString());
     125                    Logging.warn("Will not use disk cache");
     126                }
    125127            }
    126         }
     128        } catch (SecurityException e) {
     129            Logging.log(Logging.LEVEL_WARN, "Unable to configure disk cache. Will not use it", e);
     130        }
     131
    127132        // this could be moved to external file
    128133        Properties props = new Properties();
     
    140145        props.setProperty("jcs.default.elementattributes.IsSpool",            "true");
    141146        // CHECKSTYLE.ON: SingleSpaceSeparator
    142         CompositeCacheManager cm = CompositeCacheManager.getUnconfiguredInstance();
    143         cm.configure(props);
    144         cacheManager = cm;
     147        try {
     148            CompositeCacheManager cm = CompositeCacheManager.getUnconfiguredInstance();
     149            cm.configure(props);
     150            cacheManager = cm;
     151        } catch (SecurityException e) {
     152            Logging.log(Logging.LEVEL_WARN, "Unable to initialize JCS", e);
     153        }
    145154    }
    146155
     
    173182            if (cacheManager == null)
    174183                initialize();
    175             return getCacheInner(cacheName, maxMemoryObjects, maxDiskObjects, cachePath);
     184            return cacheManager != null ? getCacheInner(cacheName, maxMemoryObjects, maxDiskObjects, cachePath) : null;
    176185        }
    177186    }
Note: See TracChangeset for help on using the changeset viewer.