Index: applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/oauth/OAuthPortListener.java
===================================================================
--- applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/oauth/OAuthPortListener.java	(revision 31482)
+++ applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/oauth/OAuthPortListener.java	(revision 31486)
@@ -19,4 +19,6 @@
  */
 public class OAuthPortListener extends Thread {
+
+  protected static String RESPONSE = "<html><head><title>Mapillary login</title></head><body>Login successful, return to JOSM.</body></html>";
 
   @Override
@@ -58,7 +60,8 @@
           + accessToken);
       // Saves the access token in preferences.
-      Main.pref.put("mapillary.access-token", accessToken);
-
-      Main.info("The username is: " + MapillaryUser.getUsername());
+      if (Main.main != null) {
+        Main.pref.put("mapillary.access-token", accessToken);
+        Main.info("The username is: " + MapillaryUser.getUsername());
+      }
 
     } catch (BindException e) {
@@ -70,9 +73,8 @@
 
   private static void writeContent(PrintWriter out) {
-    String response = "<html><head><title>Mapillary login</title></head><body>Login successful, return to JOSM.</body></html>";
     out.println("HTTP/1.1 200 OK");
-    out.println("Content-Length: " + response.length());
+    out.println("Content-Length: " + RESPONSE.length());
     out.println("Content-Type: text/html" + "\r\n\r\n");
-    out.println(response);
+    out.println(RESPONSE);
   }
 }
