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

cwylie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-druid.git


The following commit(s) were added to refs/heads/master by this push:
     new 58f9507  Improper equals override is fixed to prevent 
NullPointerException (#6938)
58f9507 is described below

commit 58f9507ccf4631218359847f9fbef3e53bfc763d
Author: Furkan KAMACI <furkankam...@gmail.com>
AuthorDate: Thu Feb 7 01:08:51 2019 +0300

    Improper equals override is fixed to prevent NullPointerException (#6938)
    
    * Improper equals override is fixed to prevent NullPointerException
    
    * Fixed curly brace indentation.
    
    * Test method is added for equals method of TaskLockPosse class.
---
 .../druid/indexing/overlord/TaskLockbox.java       | 11 +++-----
 .../druid/indexing/overlord/TaskLockboxTest.java   | 30 ++++++++++++++++++++++
 2 files changed, 34 insertions(+), 7 deletions(-)

diff --git 
a/indexing-service/src/main/java/org/apache/druid/indexing/overlord/TaskLockbox.java
 
b/indexing-service/src/main/java/org/apache/druid/indexing/overlord/TaskLockbox.java
index b8402fa..787852d 100644
--- 
a/indexing-service/src/main/java/org/apache/druid/indexing/overlord/TaskLockbox.java
+++ 
b/indexing-service/src/main/java/org/apache/druid/indexing/overlord/TaskLockbox.java
@@ -1073,16 +1073,13 @@ public class TaskLockbox
         return true;
       }
 
-      if (!getClass().equals(o.getClass())) {
+      if (o == null || !getClass().equals(o.getClass())) {
         return false;
       }
 
-      final TaskLockPosse that = (TaskLockPosse) o;
-      if (!taskLock.equals(that.taskLock)) {
-        return false;
-      }
-
-      return taskIds.equals(that.taskIds);
+      TaskLockPosse that = (TaskLockPosse) o;
+      return java.util.Objects.equals(taskLock, that.taskLock) &&
+              java.util.Objects.equals(taskIds, that.taskIds);
     }
 
     @Override
diff --git 
a/indexing-service/src/test/java/org/apache/druid/indexing/overlord/TaskLockboxTest.java
 
b/indexing-service/src/test/java/org/apache/druid/indexing/overlord/TaskLockboxTest.java
index 5604255..a2a14a0 100644
--- 
a/indexing-service/src/test/java/org/apache/druid/indexing/overlord/TaskLockboxTest.java
+++ 
b/indexing-service/src/test/java/org/apache/druid/indexing/overlord/TaskLockboxTest.java
@@ -667,6 +667,36 @@ public class TaskLockboxTest
     Assert.assertTrue(lowLockPosse.getTaskLock().isRevoked());
   }
 
+  @Test
+  public void testLockPosseEquals()
+  {
+    final Task task1 = NoopTask.create();
+    final Task task2 = NoopTask.create();
+
+    TaskLock taskLock1 = new TaskLock(TaskLockType.EXCLUSIVE,
+        task1.getGroupId(),
+        task1.getDataSource(),
+        Intervals.of("2018/2019"),
+        "v1",
+        task1.getPriority());
+
+    TaskLock taskLock2 = new TaskLock(TaskLockType.EXCLUSIVE,
+        task2.getGroupId(),
+        task2.getDataSource(),
+        Intervals.of("2018/2019"),
+        "v2",
+        task2.getPriority());
+
+    TaskLockPosse taskLockPosse1 = new TaskLockPosse(taskLock1);
+    TaskLockPosse taskLockPosse2 = new TaskLockPosse(taskLock2);
+    TaskLockPosse taskLockPosse3 = new TaskLockPosse(taskLock1);
+
+    Assert.assertNotEquals(taskLockPosse1, null);
+    Assert.assertNotEquals(null, taskLockPosse1);
+    Assert.assertNotEquals(taskLockPosse1, taskLockPosse2);
+    Assert.assertEquals(taskLockPosse1, taskLockPosse3);
+  }
+
   private Set<TaskLock> getAllLocks(List<Task> tasks)
   {
     return tasks.stream()


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@druid.apache.org
For additional commands, e-mail: commits-h...@druid.apache.org

Reply via email to