Index: /trunk/src/org/openstreetmap/josm/gui/io/UploadPrimitivesTask.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/io/UploadPrimitivesTask.java	(revision 11617)
+++ /trunk/src/org/openstreetmap/josm/gui/io/UploadPrimitivesTask.java	(revision 11618)
@@ -40,5 +40,5 @@
 /**
  * The task for uploading a collection of primitives.
- *
+ * @since 2599
  */
 public class UploadPrimitivesTask extends AbstractUploadTask {
@@ -133,14 +133,15 @@
         case 0: return MaxChangesetSizeExceededPolicy.AUTOMATICALLY_OPEN_NEW_CHANGESETS;
         case 1: return MaxChangesetSizeExceededPolicy.FILL_ONE_CHANGESET_AND_RETURN_TO_UPLOAD_DIALOG;
-        case 2: return MaxChangesetSizeExceededPolicy.ABORT;
-        case JOptionPane.CLOSED_OPTION: return MaxChangesetSizeExceededPolicy.ABORT;
-        }
-        // should not happen
-        return null;
-    }
-
+        case 2:
+        case JOptionPane.CLOSED_OPTION:
+        default: return MaxChangesetSizeExceededPolicy.ABORT;
+        }
+    }
+
+    /**
+     * Opens a new changeset.
+     */
     protected void openNewChangeset() {
         // make sure the current changeset is removed from the upload dialog.
-        //
         ChangesetCache.getInstance().update(changeset);
         Changeset newChangeSet = new Changeset();
@@ -149,5 +150,5 @@
     }
 
-    protected boolean recoverFromChangesetFullException() {
+    protected boolean recoverFromChangesetFullException() throws OsmTransferException {
         if (toUpload.getSize() - processedPrimitives.size() == 0) {
             strategy.setPolicy(MaxChangesetSizeExceededPolicy.ABORT);
@@ -155,25 +156,19 @@
         }
         if (strategy.getPolicy() == null || strategy.getPolicy().equals(MaxChangesetSizeExceededPolicy.ABORT)) {
-            MaxChangesetSizeExceededPolicy policy = askMaxChangesetSizeExceedsPolicy();
-            strategy.setPolicy(policy);
+            strategy.setPolicy(askMaxChangesetSizeExceedsPolicy());
         }
         switch(strategy.getPolicy()) {
-        case ABORT:
-            // don't continue - finish() will send the user back to map editing
-            //
-            return false;
-        case FILL_ONE_CHANGESET_AND_RETURN_TO_UPLOAD_DIALOG:
-            // don't continue - finish() will send the user back to the upload dialog
-            //
-            return false;
         case AUTOMATICALLY_OPEN_NEW_CHANGESETS:
             // prepare the state of the task for a next iteration in uploading.
-            //
+            closeChangesetIfRequired();
             openNewChangeset();
             toUpload.removeProcessed(processedPrimitives);
             return true;
-        }
-        // should not happen
-        return false;
+        case ABORT:
+        case FILL_ONE_CHANGESET_AND_RETURN_TO_UPLOAD_DIALOG:
+        default:
+            // don't continue - finish() will send the user back to map editing or upload dialog
+            return false;
+        }
     }
 
@@ -250,5 +245,4 @@
 
                     // if we get here we've successfully uploaded the data. Exit the loop.
-                    //
                     break;
                 } catch (OsmTransferCanceledException e) {
@@ -258,5 +252,4 @@
                 } catch (OsmApiPrimitiveGoneException e) {
                     // try to recover from  410 Gone
-                    //
                     recoverFromGoneOnServer(e, getProgressMonitor());
                 } catch (ChangesetClosedException e) {
@@ -264,20 +257,9 @@
                         processedPrimitives.addAll(writer.getProcessedPrimitives()); // OsmPrimitive in => OsmPrimitive out
                     }
-                    changeset.setOpen(false);
                     switch(e.getSource()) {
-                    case UNSPECIFIED:
-                        throw e;
-                    case UPDATE_CHANGESET:
-                        // The changeset was closed when we tried to update it. Probably, our
-                        // local list of open changesets got out of sync with the server state.
-                        // The user will have to select another open changeset.
-                        // Rethrow exception - this will be handled later.
-                        //
-                        throw e;
                     case UPLOAD_DATA:
                         // Most likely the changeset is full. Try to recover and continue
                         // with a new changeset, but let the user decide first (see
                         // recoverFromChangesetFullException)
-                        //
                         if (recoverFromChangesetFullException()) {
                             continue;
@@ -285,4 +267,13 @@
                         lastException = e;
                         break uploadloop;
+                    case UNSPECIFIED:
+                    case UPDATE_CHANGESET:
+                    default:
+                        // The changeset was closed when we tried to update it. Probably, our
+                        // local list of open changesets got out of sync with the server state.
+                        // The user will have to select another open changeset.
+                        // Rethrow exception - this will be handled later.
+                        changeset.setOpen(false);
+                        throw e;
                     }
                 } finally {
@@ -296,8 +287,5 @@
             }
             // if required close the changeset
-            //
-            if (strategy.isCloseChangesetAfterUpload() && changeset != null && !changeset.isNew() && changeset.isOpen()) {
-                OsmApi.getOsmApi().closeChangeset(changeset, progressMonitor.createSubTaskMonitor(0, false));
-            }
+            closeChangesetIfRequired();
         } catch (OsmTransferException e) {
             if (uploadCanceled) {
@@ -309,4 +297,10 @@
         if (uploadCanceled && processedPrimitives.isEmpty()) return;
         cleanupAfterUpload();
+    }
+
+    private void closeChangesetIfRequired() throws OsmTransferException {
+        if (strategy.isCloseChangesetAfterUpload() && changeset != null && !changeset.isNew() && changeset.isOpen()) {
+            OsmApi.getOsmApi().closeChangeset(changeset, progressMonitor.createSubTaskMonitor(0, false));
+        }
     }
 
