kafka-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From guozh...@apache.org
Subject kafka git commit: KAFKA-2974; `==` is used incorrectly in a few places in Java code
Date Thu, 10 Dec 2015 04:35:12 GMT
Repository: kafka
Updated Branches:
  refs/heads/0.9.0 83c1e33aa -> a5fa66122


KAFKA-2974; `==` is used incorrectly in a few places in Java code

A few issues found via static analysis.

Author: Edward Ribeiro <edward.ribeiro@gmail.com>
Author: Ismael Juma <ismael@juma.me.uk>

Reviewers: Gwen Shapira, Sriharsha Chintalapani, Guozhang Wang

Closes #652 from ijuma/use-equals-instead-of-==

(cherry picked from commit 6e5bd2497af2b6bb67a47e4f3defa50da3cad4c7)
Signed-off-by: Guozhang Wang <wangguoz@gmail.com>


Project: http://git-wip-us.apache.org/repos/asf/kafka/repo
Commit: http://git-wip-us.apache.org/repos/asf/kafka/commit/a5fa6612
Tree: http://git-wip-us.apache.org/repos/asf/kafka/tree/a5fa6612
Diff: http://git-wip-us.apache.org/repos/asf/kafka/diff/a5fa6612

Branch: refs/heads/0.9.0
Commit: a5fa661227b0b0b7da86b10b48e94bfb87d0b71d
Parents: 83c1e33
Author: Edward Ribeiro <edward.ribeiro@gmail.com>
Authored: Wed Dec 9 20:34:09 2015 -0800
Committer: Guozhang Wang <wangguoz@gmail.com>
Committed: Wed Dec 9 20:35:08 2015 -0800

----------------------------------------------------------------------
 .../kafka/common/security/kerberos/LoginManager.java  |  2 +-
 .../java/org/apache/kafka/clients/MockClient.java     | 14 +++++++-------
 .../kafka/clients/producer/internals/SenderTest.java  |  8 +++++++-
 .../org/apache/kafka/common/network/SelectorTest.java |  2 +-
 .../org/apache/kafka/connect/data/SchemaBuilder.java  |  2 +-
 5 files changed, 17 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kafka/blob/a5fa6612/clients/src/main/java/org/apache/kafka/common/security/kerberos/LoginManager.java
----------------------------------------------------------------------
diff --git a/clients/src/main/java/org/apache/kafka/common/security/kerberos/LoginManager.java
b/clients/src/main/java/org/apache/kafka/common/security/kerberos/LoginManager.java
index ac31f9f..cf68d20 100644
--- a/clients/src/main/java/org/apache/kafka/common/security/kerberos/LoginManager.java
+++ b/clients/src/main/java/org/apache/kafka/common/security/kerberos/LoginManager.java
@@ -49,7 +49,7 @@ public class LoginManager {
     private static String getServiceName(String loginContext, Map<String, ?> configs)
throws IOException {
         String jaasServiceName = JaasUtils.jaasConfig(loginContext, JaasUtils.SERVICE_NAME);
         String configServiceName = (String) configs.get(SaslConfigs.SASL_KERBEROS_SERVICE_NAME);
-        if (jaasServiceName != null && configServiceName != null && jaasServiceName
!= configServiceName) {
+        if (jaasServiceName != null && configServiceName != null && !jaasServiceName.equals(configServiceName))
{
             String message = "Conflicting serviceName values found in JAAS and Kafka configs
" +
                 "value in JAAS file " + jaasServiceName + ", value in Kafka config " + configServiceName;
             throw new IllegalArgumentException(message);

http://git-wip-us.apache.org/repos/asf/kafka/blob/a5fa6612/clients/src/test/java/org/apache/kafka/clients/MockClient.java
----------------------------------------------------------------------
diff --git a/clients/src/test/java/org/apache/kafka/clients/MockClient.java b/clients/src/test/java/org/apache/kafka/clients/MockClient.java
index 2726e87..1c3efd4 100644
--- a/clients/src/test/java/org/apache/kafka/clients/MockClient.java
+++ b/clients/src/test/java/org/apache/kafka/clients/MockClient.java
@@ -57,7 +57,7 @@ public class MockClient implements KafkaClient {
     private final Time time;
     private int correlation = 0;
     private Node node = null;
-    private final Set<Integer> ready = new HashSet<>();
+    private final Set<String> ready = new HashSet<>();
     private final Queue<ClientRequest> requests = new ArrayDeque<>();
     private final Queue<ClientResponse> responses = new ArrayDeque<>();
     private final Queue<FutureResponse> futureResponses = new ArrayDeque<>();
@@ -68,12 +68,12 @@ public class MockClient implements KafkaClient {
 
     @Override
     public boolean isReady(Node node, long now) {
-        return ready.contains(node.id());
+        return ready.contains(node.idString());
     }
 
     @Override
     public boolean ready(Node node, long now) {
-        ready.add(node.id());
+        ready.add(node.idString());
         return true;
     }
 
@@ -92,7 +92,7 @@ public class MockClient implements KafkaClient {
         Iterator<ClientRequest> iter = requests.iterator();
         while (iter.hasNext()) {
             ClientRequest request = iter.next();
-            if (request.request().destination() == node) {
+            if (request.request().destination().equals(node)) {
                 responses.add(new ClientResponse(request, now, true, null));
                 iter.remove();
             }
@@ -180,7 +180,7 @@ public class MockClient implements KafkaClient {
     }
 
     @Override
-    public int inFlightRequestCount(String nodeId) {
+    public int inFlightRequestCount(String node) {
         return requests.size();
     }
 
@@ -203,8 +203,8 @@ public class MockClient implements KafkaClient {
     }
 
     @Override
-    public void close(String nodeId) {
-        ready.remove(Integer.valueOf(nodeId));
+    public void close(String node) {
+        ready.remove(node);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/kafka/blob/a5fa6612/clients/src/test/java/org/apache/kafka/clients/producer/internals/SenderTest.java
----------------------------------------------------------------------
diff --git a/clients/src/test/java/org/apache/kafka/clients/producer/internals/SenderTest.java
b/clients/src/test/java/org/apache/kafka/clients/producer/internals/SenderTest.java
index bcc618a..05bbd73 100644
--- a/clients/src/test/java/org/apache/kafka/clients/producer/internals/SenderTest.java
+++ b/clients/src/test/java/org/apache/kafka/clients/producer/internals/SenderTest.java
@@ -14,6 +14,7 @@ package org.apache.kafka.clients.producer.internals;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.fail;
 
 import java.util.Collections;
@@ -27,6 +28,7 @@ import org.apache.kafka.clients.MockClient;
 import org.apache.kafka.clients.producer.RecordMetadata;
 import org.apache.kafka.common.Cluster;
 import org.apache.kafka.common.MetricName;
+import org.apache.kafka.common.Node;
 import org.apache.kafka.common.TopicPartition;
 import org.apache.kafka.common.metrics.KafkaMetric;
 import org.apache.kafka.common.metrics.Metrics;
@@ -136,9 +138,13 @@ public class SenderTest {
             Future<RecordMetadata> future = accumulator.append(tp, "key".getBytes(),
"value".getBytes(), null, MAX_BLOCK_TIMEOUT).future;
             sender.run(time.milliseconds()); // connect
             sender.run(time.milliseconds()); // send produce request
+            String id = client.requests().peek().request().destination();
+            Node node = new Node(Integer.valueOf(id), "localhost", 0);
             assertEquals(1, client.inFlightRequestCount());
-            client.disconnect(client.requests().peek().request().destination());
+            assertTrue("Client ready status should be true", client.isReady(node, 0L));
+            client.disconnect(id);
             assertEquals(0, client.inFlightRequestCount());
+            assertFalse("Client ready status should be false", client.isReady(node, 0L));
             sender.run(time.milliseconds()); // receive error
             sender.run(time.milliseconds()); // reconnect
             sender.run(time.milliseconds()); // resend

http://git-wip-us.apache.org/repos/asf/kafka/blob/a5fa6612/clients/src/test/java/org/apache/kafka/common/network/SelectorTest.java
----------------------------------------------------------------------
diff --git a/clients/src/test/java/org/apache/kafka/common/network/SelectorTest.java b/clients/src/test/java/org/apache/kafka/common/network/SelectorTest.java
index 18fd080..b87762a 100644
--- a/clients/src/test/java/org/apache/kafka/common/network/SelectorTest.java
+++ b/clients/src/test/java/org/apache/kafka/common/network/SelectorTest.java
@@ -268,7 +268,7 @@ public class SelectorTest {
         while (true) {
             selector.poll(1000L);
             for (NetworkReceive receive : selector.completedReceives())
-                if (receive.source() == node)
+                if (receive.source().equals(node))
                     return asString(receive);
         }
     }

http://git-wip-us.apache.org/repos/asf/kafka/blob/a5fa6612/connect/api/src/main/java/org/apache/kafka/connect/data/SchemaBuilder.java
----------------------------------------------------------------------
diff --git a/connect/api/src/main/java/org/apache/kafka/connect/data/SchemaBuilder.java b/connect/api/src/main/java/org/apache/kafka/connect/data/SchemaBuilder.java
index b063c51..3d2f5cc 100644
--- a/connect/api/src/main/java/org/apache/kafka/connect/data/SchemaBuilder.java
+++ b/connect/api/src/main/java/org/apache/kafka/connect/data/SchemaBuilder.java
@@ -338,7 +338,7 @@ public class SchemaBuilder implements Schema {
         if (type != Type.STRUCT)
             throw new DataException("Cannot look up fields on non-struct type");
         for (Field field : fields)
-            if (field.name() == fieldName)
+            if (field.name().equals(fieldName))
                 return field;
         return null;
     }


Mime
View raw message