Przeglądaj źródła

ZOOKEEPER-2825: 1. Remove unnecessary import; 2. `contains` instead of `indexOf > -1` for more readable; 3. Standardize `StringBuilder#append` usage for CLIENT module

* Remove unnecessary import;
* `contains` instead of `indexOf > -1` for more readable;
* Standardize `StringBuilder#append` usage for CLIENT module

Author: asdf2014 <benedictjin2016@gmail.com>

Reviewers: afine@apache.org, andor@apache.org

Closes #297 from asdf2014/ZOOKEEPER-2825
asdf2014 6 lat temu
rodzic
commit
cbc63dbaad

+ 2 - 2
zookeeper-server/src/main/java/org/apache/zookeeper/ClientCnxn.java

@@ -1180,7 +1180,7 @@ public class ClientCnxn {
                                 }
                             }
 
-                            if (sendAuthEvent == true) {
+                            if (sendAuthEvent) {
                                 eventThread.queueEvent(new WatchedEvent(
                                       Watcher.Event.EventType.None,
                                       authState,null));
@@ -1433,7 +1433,7 @@ public class ClientCnxn {
             }
 
             // 2. SASL login failed.
-            if (saslLoginFailed == true) {
+            if (saslLoginFailed) {
                 return false;
             }
 

+ 1 - 1
zookeeper-server/src/main/java/org/apache/zookeeper/client/FourLetterWordMain.java

@@ -122,7 +122,7 @@ public class FourLetterWordMain {
             StringBuilder sb = new StringBuilder();
             String line;
             while((line = reader.readLine()) != null) {
-                sb.append(line + "\n");
+                sb.append(line).append("\n");
             }
             return sb.toString();
         } catch (SocketTimeoutException e) {

+ 0 - 1
zookeeper-server/src/main/java/org/apache/zookeeper/client/HostProvider.java

@@ -21,7 +21,6 @@ package org.apache.zookeeper.client;
 import org.apache.yetus.audience.InterfaceAudience;
 
 import java.net.InetSocketAddress;
-import java.net.UnknownHostException;
 import java.util.Collection;
 
 /**

+ 6 - 9
zookeeper-server/src/main/java/org/apache/zookeeper/client/ZooKeeperSaslClient.java

@@ -332,7 +332,7 @@ public class ZooKeeperSaslClient {
                     // TODO: introspect about e: look for GSS information.
                     final String UNKNOWN_SERVER_ERROR_TEXT =
                       "(Mechanism level: Server not found in Kerberos database (7) - UNKNOWN_SERVER)";
-                    if (e.toString().indexOf(UNKNOWN_SERVER_ERROR_TEXT) > -1) {
+                    if (e.toString().contains(UNKNOWN_SERVER_ERROR_TEXT)) {
                         error += " This may be caused by Java's being unable to resolve the Zookeeper Quorum Member's" +
                           " hostname correctly. You may want to try to adding" +
                           " '-Dsun.net.spi.nameservice.provider.1=dns,sun' to your client's JVMFLAGS environment.";
@@ -438,18 +438,15 @@ public class ZooKeeperSaslClient {
                 // authentication is either in progress, successful, or failed.
 
                 // 1. Authentication hasn't finished yet: we must wait for it to do so.
-                if ((isComplete() == false) &&
-                    (isFailed() == false)) {
+                if (!isComplete() && !isFailed()) {
                     return true;
                 }
 
                 // 2. SASL authentication has succeeded or failed..
-                if (isComplete() || isFailed()) {
-                    if (gotLastPacket == false) {
-                        // ..but still in progress, because there is a final SASL
-                        // message from server which must be received.
+                if (!gotLastPacket) {
+                    // ..but still in progress, because there is a final SASL
+                    // message from server which must be received.
                     return true;
-                    }
                 }
             }
             // Either client is not configured to use a tunnelled authentication
@@ -459,7 +456,7 @@ public class ZooKeeperSaslClient {
         } catch (SecurityException e) {
             // Thrown if the caller does not have permission to retrieve the Configuration.
             // In this case, simply returning false is correct.
-            if (LOG.isDebugEnabled() == true) {
+            if (LOG.isDebugEnabled()) {
                 LOG.debug("Could not retrieve login configuration: " + e);
             }
             return false;