Sonar suggestion - don't lock on a field that is being modified

This code could also throw an NPE if called at the wrong time.
Fixed by saving the value to lock on before saving the new value.

Change-Id: I6a7570c00135d7cff31f3429af1067f4228e5189
diff --git a/protocols/lisp/api/src/main/java/org/onosproject/lisp/ctl/LispRouterFactory.java b/protocols/lisp/api/src/main/java/org/onosproject/lisp/ctl/LispRouterFactory.java
index 4dc9da1..bf7dfb6 100644
--- a/protocols/lisp/api/src/main/java/org/onosproject/lisp/ctl/LispRouterFactory.java
+++ b/protocols/lisp/api/src/main/java/org/onosproject/lisp/ctl/LispRouterFactory.java
@@ -58,12 +58,13 @@
      * Cleans up LISP router agent.
      */
     public void cleanAgent() {
-        synchronized (agent) {
-            if (this.agent != null) {
-                this.agent = null;
-            } else {
-                log.warn("LISP Router Agent is not configured.");
-            }
+        if (this.agent == null) {
+            log.warn("LISP Router Agent is not configured.");
+            return;
+        }
+        LispRouterAgent existingAgent = agent;
+        synchronized (existingAgent) {
+            this.agent = null;
         }
     }