Index: /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionBoundaries.java
===================================================================
--- /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionBoundaries.java	(revision 34667)
+++ /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionBoundaries.java	(revision 34668)
@@ -2,4 +2,5 @@
 package org.openstreetmap.josm.plugins.fr.cadastre.actions;
 
+import static org.openstreetmap.josm.tools.I18n.marktr;
 import static org.openstreetmap.josm.tools.I18n.tr;
 
@@ -13,7 +14,10 @@
 import org.openstreetmap.josm.plugins.fr.cadastre.wms.WMSLayer;
 
+/**
+ * Extract commune boundary
+ */
 public class MenuActionBoundaries extends JosmAction {
 
-    public static final String NAME = "Administrative boundary";
+    private static final String NAME = marktr("Administrative boundary");
 
     private static final long serialVersionUID = 1L;
Index: /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionCancelGrab.java
===================================================================
--- /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionCancelGrab.java	(revision 34667)
+++ /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionCancelGrab.java	(revision 34668)
@@ -10,8 +10,10 @@
 import org.openstreetmap.josm.plugins.fr.cadastre.wms.WMSLayer;
 
-@SuppressWarnings("serial")
+/**
+ * Cancel current grab (only vector images)
+ */
 public class MenuActionCancelGrab extends JosmAction {
 
-    public static final String NAME = marktr("Cancel current grab");
+    private static final String NAME = marktr("Cancel current grab");
 
     private WMSLayer wmsLayer;
Index: /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionGrab.java
===================================================================
--- /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionGrab.java	(revision 34667)
+++ /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionGrab.java	(revision 34668)
@@ -20,5 +20,5 @@
 public class MenuActionGrab extends JosmAction {
 
-    public static final String NAME = marktr("Cadastre grab");
+    private static final String NAME = marktr("Cadastre grab");
 
     /**
Index: /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionGrabPlanImage.java
===================================================================
--- /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionGrabPlanImage.java	(revision 34667)
+++ /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionGrabPlanImage.java	(revision 34668)
@@ -18,4 +18,7 @@
 import org.openstreetmap.josm.spi.preferences.Config;
 
+/**
+ * Grab non-georeferenced image
+ */
 public class MenuActionGrabPlanImage extends JosmAction implements Runnable {
 
Index: /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionLoadFromCache.java
===================================================================
--- /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionLoadFromCache.java	(revision 34667)
+++ /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionLoadFromCache.java	(revision 34668)
@@ -22,8 +22,11 @@
 import org.openstreetmap.josm.tools.Logging;
 
+/**
+ * Load location from cache (only if cache is enabled)
+ */
 public class MenuActionLoadFromCache extends JosmAction {
     private static final long serialVersionUID = 1L;
 
-    public static final String name = marktr("Load layer from cache");
+    private static final String name = marktr("Load layer from cache");
 
     /**
@@ -49,8 +52,8 @@
                 String ext = (filename.lastIndexOf('.') == -1) ? "" : filename.substring(filename.lastIndexOf('.')+1, filename.length());
                 if ((ext.length() == 3 && ext.substring(0, CacheControl.C_LAMBERT_CC_9Z.length()).equals(CacheControl.C_LAMBERT_CC_9Z) &&
-                    !(CadastrePlugin.isLambert_cc9()))
+                    !CadastrePlugin.isLambert_cc9())
                     || (ext.length() == 4 && ext.substring(0, CacheControl.C_UTM20N.length()).equals(CacheControl.C_UTM20N) &&
                             !(CadastrePlugin.isUtm_france_dom()))
-                    || (ext.length() == 1) && !(CadastrePlugin.isLambert())) {
+                    || (ext.length() == 1 && !CadastrePlugin.isLambert())) {
                         JOptionPane.showMessageDialog(MainApplication.getMainFrame(),
                                 tr("{0} not allowed with the current projection", filename),
Index: /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionNewLocation.java
===================================================================
--- /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionNewLocation.java	(revision 34667)
+++ /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionNewLocation.java	(revision 34668)
@@ -24,4 +24,7 @@
 import org.openstreetmap.josm.tools.Logging;
 
+/**
+ * Set a new location for the next request
+ */
 public class MenuActionNewLocation extends JosmAction {
 
@@ -59,4 +62,7 @@
     // CHECKSTYLE.ON: LineLength
 
+    /**
+     * Constructs a new {@code MenuActionNewLocation}.
+     */
     public MenuActionNewLocation() {
         super(tr("Change location"), "cadastre_small", tr("Set a new location for the next request"), null, false,
Index: /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionOpenPreferences.java
===================================================================
--- /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionOpenPreferences.java	(revision 34667)
+++ /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionOpenPreferences.java	(revision 34668)
@@ -12,8 +12,10 @@
 import org.openstreetmap.josm.plugins.fr.cadastre.preferences.CadastrePreferenceSetting;
 
+/**
+ * Open Cadastre Preferences
+ */
 public class MenuActionOpenPreferences extends JosmAction {
-    private static final long serialVersionUID = 1L;
 
-    public static final String NAME = marktr("Preferences");
+    private static final String NAME = marktr("Preferences");
 
     /**
Index: /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionRefineGeoRef.java
===================================================================
--- /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionRefineGeoRef.java	(revision 34667)
+++ /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionRefineGeoRef.java	(revision 34668)
@@ -13,7 +13,10 @@
 import org.openstreetmap.josm.tools.Logging;
 
+/**
+ * Improve georeferencing (only raster images)
+ */
 public class MenuActionRefineGeoRef extends JosmAction {
 
-    public static final String NAME = marktr("Refine georeferencing");
+    private static final String NAME = marktr("Refine georeferencing");
 
     private WMSLayer wmsLayer;
Index: /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionResetCookie.java
===================================================================
--- /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionResetCookie.java	(revision 34667)
+++ /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionResetCookie.java	(revision 34668)
@@ -8,11 +8,12 @@
 import org.openstreetmap.josm.actions.JosmAction;
 
+/**
+ * Get a new cookie (session timeout)
+ */
 public class MenuActionResetCookie extends JosmAction {
 
     /**
-     *
+     * Constructs a new {@code MenuActionResetCookie}
      */
-    private static final long serialVersionUID = 1L;
-
     public MenuActionResetCookie() {
         super(tr("Reset cookie"), "cadastre_small", tr("Get a new cookie (session timeout)"), null, false);
Index: /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionSaveRasterAs.java
===================================================================
--- /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionSaveRasterAs.java	(revision 34667)
+++ /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionSaveRasterAs.java	(revision 34668)
@@ -30,13 +30,14 @@
 import org.openstreetmap.josm.tools.Logging;
 
+/**
+ * Export image (only raster images)
+ */
 public class MenuActionSaveRasterAs extends JosmAction {
 
-    public static final String NAME = marktr("Save image as...");
-
-    private static final long serialVersionUID = 1L;
+    private static final String NAME = marktr("Save image as...");
 
     private WMSLayer wmsLayer;
 
-    public static class FiltrePng extends FileFilter {
+    static class FiltrePng extends FileFilter {
         @Override
         public boolean accept(File file) {
@@ -53,5 +54,5 @@
     }
 
-    public static class FiltreTiff extends FileFilter {
+    static class FiltreTiff extends FileFilter {
         @Override
         public boolean accept(File file) {
@@ -96,11 +97,4 @@
                 try {
                     ImageIO.write(bi, "png", file);
-                    /*
-                    FileOutputStream flux = new FileOutputStream(file);
-                    BufferedOutputStream fluxBuf = new BufferedOutputStream(flux);
-                    JPEGImageEncoder codec = JPEGCodec.createJPEGEncoder(fluxBuf, JPEGCodec.getDefaultJPEGEncodeParam(bi));
-                    codec.encode(bi);
-                    fluxBuf.close();
-                    */
                 } catch (IOException e) {
                     Logging.error(e);
Index: /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/edigeo/EdigeoRecord.java
===================================================================
--- /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/edigeo/EdigeoRecord.java	(revision 34667)
+++ /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/edigeo/EdigeoRecord.java	(revision 34668)
@@ -10,5 +10,5 @@
  * Edigeo record.
  */
-class EdigeoRecord {
+final class EdigeoRecord {
 
     enum Nature {
Index: /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/CacheControl.java
===================================================================
--- /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/CacheControl.java	(revision 34667)
+++ /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/CacheControl.java	(revision 34668)
@@ -64,7 +64,9 @@
     public boolean isCachePipeEmpty() {
         imagesLock.lock();
-        boolean ret = imagesToSave.isEmpty();
-        imagesLock.unlock();
-        return ret;
+        try {
+            return imagesToSave.isEmpty();
+        } finally {
+            imagesLock.unlock();
+        }
     }
 
@@ -159,5 +161,6 @@
             ObjectInputStream ois = new ObjectInputStream(fis);
         ) {
-            successfulRead = wmsLayer.read(file, ois, currentLambertZone);
+            wmsLayer.setAssociatedFile(file);
+            successfulRead = wmsLayer.read(ois, currentLambertZone);
         } catch (IOException | ClassNotFoundException ex) {
             Logging.error(ex);
@@ -176,7 +179,10 @@
     public synchronized void saveCache(GeorefImage image) {
         imagesLock.lock();
-        this.imagesToSave.add(image);
-        this.notifyAll();
-        imagesLock.unlock();
+        try {
+            this.imagesToSave.add(image);
+            this.notifyAll();
+        } finally {
+            imagesLock.unlock();
+        }
     }
 
@@ -203,5 +209,6 @@
                         try (ObjectOutputStream oos = new ObjectOutputStream(
                                 new BufferedOutputStream(new FileOutputStream(file)))) {
-                            wmsLayer.write(file, oos);
+                            wmsLayer.setAssociatedFile(file);
+                            wmsLayer.write(oos);
                             for (int i = 0; i < size; i++) {
                                 oos.writeObject(imagesToSave.get(i));
@@ -213,8 +220,11 @@
                 }
                 imagesLock.lock();
-                for (int i = 0; i < size; i++) {
-                    imagesToSave.remove(0);
-                }
-                imagesLock.unlock();
+                try {
+                    for (int i = 0; i < size; i++) {
+                        imagesToSave.remove(0);
+                    }
+                } finally {
+                    imagesLock.unlock();
+                }
             }
             try {
Index: /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/CadastreInterface.java
===================================================================
--- /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/CadastreInterface.java	(revision 34667)
+++ /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/CadastreInterface.java	(revision 34668)
@@ -536,5 +536,5 @@
         if (MainApplication.getMap() != null) {
             for (Layer l : MainApplication.getLayerManager().getLayers()) {
-                if (l instanceof WMSLayer && l.getName().equals(wmsLayer.getName()) && (!l.equals(wmsLayer))) {
+                if (l instanceof WMSLayer && l.getName().equals(wmsLayer.getName()) && !l.equals(wmsLayer)) {
                     Logging.info("Try to grab into a new layer when "+wmsLayer.getName()+" is already opened.");
                     // remove the duplicated layer
Index: /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/GrabThread.java
===================================================================
--- /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/GrabThread.java	(revision 34667)
+++ /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/GrabThread.java	(revision 34668)
@@ -40,6 +40,9 @@
     void addImages(ArrayList<EastNorthBound> moreImages) {
         lockImagesToGrag.lock();
-        imagesToGrab.addAll(moreImages);
-        lockImagesToGrag.unlock();
+        try {
+            imagesToGrab.addAll(moreImages);
+        } finally {
+            lockImagesToGrag.unlock();
+        }
         synchronized (this) {
             this.notify();
@@ -53,7 +56,9 @@
     public int getImagesToGrabSize() {
         lockImagesToGrag.lock();
-        int size = imagesToGrab.size();
-        lockImagesToGrag.unlock();
-        return size;
+        try {
+            return imagesToGrab.size();
+        } finally {
+            lockImagesToGrag.unlock();
+        }
     }
 
@@ -61,9 +66,12 @@
         ArrayList<EastNorthBound> copyList = new ArrayList<>();
         lockImagesToGrag.lock();
-        for (EastNorthBound img : imagesToGrab) {
-            EastNorthBound imgCpy = new EastNorthBound(img.min, img.max);
-            copyList.add(imgCpy);
-        }
-        lockImagesToGrag.unlock();
+        try {
+            for (EastNorthBound img : imagesToGrab) {
+                EastNorthBound imgCpy = new EastNorthBound(img.min, img.max);
+                copyList.add(imgCpy);
+            }
+        } finally {
+            lockImagesToGrag.unlock();
+        }
         return copyList;
     }
@@ -71,6 +79,9 @@
     void clearImagesToGrab() {
         lockImagesToGrag.lock();
-        imagesToGrab.clear();
-        lockImagesToGrag.unlock();
+        try {
+            imagesToGrab.clear();
+        } finally {
+            lockImagesToGrag.unlock();
+        }
     }
 
@@ -109,14 +120,17 @@
                         if (CadastrePlugin.backgroundTransparent) {
                             wmsLayer.imagesLock.lock();
-                            for (GeorefImage img : wmsLayer.getImages()) {
-                                if (img.overlap(newImage))
-                                    // mask overlapping zone in already grabbed image
-                                    img.withdraw(newImage);
-                                else
-                                    // mask overlapping zone in new image only when new image covers completely the
-                                    // existing image
-                                    newImage.withdraw(img);
+                            try {
+                                for (GeorefImage img : wmsLayer.getImages()) {
+                                    if (img.overlap(newImage))
+                                        // mask overlapping zone in already grabbed image
+                                        img.withdraw(newImage);
+                                    else
+                                        // mask overlapping zone in new image only when new image covers completely the
+                                        // existing image
+                                        newImage.withdraw(img);
+                                }
+                            } finally {
+                                wmsLayer.imagesLock.unlock();
                             }
-                            wmsLayer.imagesLock.unlock();
                         }
                         wmsLayer.addImage(newImage);
Index: /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/WMSLayer.java
===================================================================
--- /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/WMSLayer.java	(revision 34667)
+++ /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/WMSLayer.java	(revision 34668)
@@ -15,5 +15,4 @@
 import java.awt.image.ImageObserver;
 import java.io.EOFException;
-import java.io.File;
 import java.io.IOException;
 import java.io.ObjectInputStream;
@@ -61,5 +60,5 @@
     private int lambertZone = -1;
 
-    public CadastreGrabber grabber = new CadastreGrabber();
+    CadastreGrabber grabber = new CadastreGrabber();
 
     protected static final Icon icon = new ImageIcon(Toolkit.getDefaultToolkit().createImage(
@@ -68,5 +67,5 @@
     private Vector<GeorefImage> images = new Vector<>();
 
-    public Lock imagesLock = new ReentrantLock();
+    Lock imagesLock = new ReentrantLock();
 
     /**
@@ -77,5 +76,5 @@
     protected final int serializeFormatVersion = 4;
 
-    public static int currentFormat;
+    static int currentFormat;
 
     private ArrayList<EastNorthBound> dividedBbox = new ArrayList<>();
@@ -87,9 +86,9 @@
     private String codeCommune = "";
 
-    public EastNorthBound communeBBox = new EastNorthBound(new EastNorth(0, 0), new EastNorth(0, 0));
+    EastNorthBound communeBBox = new EastNorthBound(new EastNorth(0, 0), new EastNorth(0, 0));
 
     private boolean isRaster;
     private boolean isAlreadyGeoreferenced;
-    public double X0, Y0, angle, fX, fY;
+    double X0, Y0, angle, fX, fY;
 
     // bbox of the georeferenced raster image (the nice horizontal and vertical box)
@@ -99,6 +98,6 @@
 
     // offset for vector images temporarily shifted (correcting Cadastre artifacts), in pixels
-    public double deltaEast;
-    public double deltaNorth;
+    double deltaEast;
+    double deltaNorth;
 
     private Action saveAsPng;
@@ -300,9 +299,12 @@
                 g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
             imagesLock.lock();
-            for (GeorefImage img : images) {
-                img.paint(g, mv, CadastrePlugin.backgroundTransparent,
-                        CadastrePlugin.transparency, CadastrePlugin.drawBoundaries);
-            }
-            imagesLock.unlock();
+            try {
+                for (GeorefImage img : images) {
+                    img.paint(g, mv, CadastrePlugin.backgroundTransparent,
+                            CadastrePlugin.transparency, CadastrePlugin.drawBoundaries);
+                }
+            } finally {
+                imagesLock.unlock();
+            }
             g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, savedInterpolation);
         }
@@ -378,4 +380,6 @@
      * The original raster size is [0,0,12286,8730] where 0,0 is the upper left corner and
      * 12286,8730 is the approx. raster max size.
+     * @param min min east/north
+     * @param max max east/north
      * @return the raster coordinates for the wms server request URL (minX,minY,maxX,maxY)
      */
@@ -456,8 +460,9 @@
      * Called by CacheControl when a new cache file is created on disk.
      * Save only primitives to keep cache independent of software changes.
-     */
-    public void write(File associatedFile, ObjectOutputStream oos) throws IOException {
+     * @param oos output stream
+     * @throws IOException if any I/O error occurs
+     */
+    public void write(ObjectOutputStream oos) throws IOException {
         currentFormat = this.serializeFormatVersion;
-        setAssociatedFile(associatedFile);
         oos.writeInt(this.serializeFormatVersion);
         oos.writeObject(this.location);    // String
@@ -482,7 +487,12 @@
      * Called by CacheControl when a cache file is read from disk.
      * Cache uses only primitives to stay independent of software changes.
-     */
-    public boolean read(File associatedFile, ObjectInputStream ois, int currentLambertZone) throws IOException, ClassNotFoundException {
-        currentFormat = ois.readInt();;
+     * @param ois input stream
+     * @param currentLambertZone current Lambert zone
+     * @return {@code true} for success
+     * @throws IOException if any I/O error occurs
+     * @throws ClassNotFoundException if class of a serialized object cannot be found
+     */
+    public boolean read(ObjectInputStream ois, int currentLambertZone) throws IOException, ClassNotFoundException {
+        currentFormat = ois.readInt();
         if (currentFormat < 2) {
             JOptionPane.showMessageDialog(MainApplication.getMainFrame(),
@@ -495,5 +505,4 @@
         this.lambertZone = ois.readInt();
         this.setRaster(ois.readBoolean());
-        setAssociatedFile(associatedFile);
         if (currentFormat >= 4)
             ois.readBoolean();
@@ -587,4 +596,6 @@
      * Works only for raster image layer (only one image in collection).
      * Updates layer georeferences.
+     * @param en1 first east/north
+     * @param en2 second east/north
      */
     public void cropImage(EastNorth en1, EastNorth en2) {
@@ -700,16 +711,16 @@
     public GeorefImage getImage(int index) {
         imagesLock.lock();
-        GeorefImage img = null;
         try {
-            img = this.images.get(index);
+            return images.get(index);
         } catch (ArrayIndexOutOfBoundsException e) {
             Logging.error(e);
-        }
-        imagesLock.unlock();
-        return img;
+            return null;
+        } finally {
+            imagesLock.unlock();
+        }
     }
 
     public Vector<GeorefImage> getImages() {
-        return this.images;
+        return images;
     }
 
@@ -720,18 +731,27 @@
     public void addImage(GeorefImage img) {
         imagesLock.lock();
-        this.images.add(img);
-        imagesLock.unlock();
+        try {
+            images.add(img);
+        } finally {
+            imagesLock.unlock();
+        }
     }
 
     public void setImages(Vector<GeorefImage> images) {
         imagesLock.lock();
-        this.images = images;
-        imagesLock.unlock();
+        try {
+            this.images = images;
+        } finally {
+            imagesLock.unlock();
+        }
     }
 
     public void clearImages() {
         imagesLock.lock();
-        this.images.clear();
-        imagesLock.unlock();
+        try {
+            images.clear();
+        } finally {
+            imagesLock.unlock();
+        }
     }
 }
