This is an automated email from the ASF dual-hosted git repository.

tison pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/curator.git


The following commit(s) were added to refs/heads/master by this push:
     new 3468ee91 CURATOR-521. Check LeaderLatch#close(CloseMode) does not 
accept null (#481)
3468ee91 is described below

commit 3468ee91561534d5a748bfb06902725542d07347
Author: tison <[email protected]>
AuthorDate: Wed Sep 20 01:01:43 2023 +0800

    CURATOR-521. Check LeaderLatch#close(CloseMode) does not accept null (#481)
    
    Signed-off-by: tison <[email protected]>
---
 .../curator/framework/recipes/leader/LeaderLatch.java   | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)

diff --git 
a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/leader/LeaderLatch.java
 
b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/leader/LeaderLatch.java
index 2c01857e..80509dbf 100644
--- 
a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/leader/LeaderLatch.java
+++ 
b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/leader/LeaderLatch.java
@@ -188,6 +188,7 @@ public class LeaderLatch implements Closeable {
      * @throws IOException errors
      */
     public void close(CloseMode closeMode) throws IOException {
+        Preconditions.checkNotNull(closeMode, "closeMode cannot be null");
         internalClose(closeMode, true);
     }
 
@@ -200,8 +201,6 @@ public class LeaderLatch implements Closeable {
             }
         }
 
-        Preconditions.checkNotNull(closeMode, "closeMode cannot be null");
-
         cancelStartTask();
 
         try {
@@ -214,17 +213,14 @@ public class LeaderLatch implements Closeable {
             client.getConnectionStateListenable().removeListener(listener);
 
             switch (closeMode) {
-                case NOTIFY_LEADER: {
+                case NOTIFY_LEADER:
                     setLeadership(false);
                     listeners.clear();
                     break;
-                }
-
-                default: {
+                case SILENT:
                     listeners.clear();
                     setLeadership(false);
                     break;
-                }
             }
         }
     }
@@ -457,13 +453,12 @@ public class LeaderLatch implements Closeable {
      * it is possible for <code>null</code> to be returned. The path, if any,
      * returned is not guaranteed to be valid at any point in the future as 
internal
      * state changes might require the instance to delete and create a new 
path.
-     *
+     * <p>
      * However, the existence of <code>ourPath</code> doesn't mean that this 
instance
      * holds leadership.
      *
-     * @see #getLastPathIsLeader
-     *
      * @return lock node path or <code>null</code>
+     * @see #getLastPathIsLeader
      */
     public String getOurPath() {
         return ourPath.get();
@@ -475,7 +470,7 @@ public class LeaderLatch implements Closeable {
      * Also, it is possible for <code>null</code> to be returned (for this 
instance never becomes
      * a leader). The path, if any, returned is not guaranteed to be valid at 
any point in the future
      * as internal state changes might require the instance to delete the path.
-     *
+     * <p>
      * The existence of <code>lastPathIsLeader</code> means that this instance 
holds leadership.
      *
      * @return last lock node path that was leader ever or <code>null</code>

Reply via email to