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

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


The following commit(s) were added to refs/heads/0.14.0-incubating by this push:
     new 6894c9f  Improper equals override is fixed to prevent 
NullPointerException (#6938) (#7022)
6894c9f is described below

commit 6894c9f7ca42624b98c3e25a8884c3155408b2a2
Author: Clint Wylie <[email protected]>
AuthorDate: Thu Feb 7 08:44:18 2019 -0800

    Improper equals override is fixed to prevent NullPointerException (#6938) 
(#7022)
    
    * 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: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to