From 58f9507ccf4631218359847f9fbef3e53bfc763d Mon Sep 17 00:00:00 2001 From: Furkan KAMACI Date: Thu, 7 Feb 2019 01:08:51 +0300 Subject: [PATCH] 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 +++---- .../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 b8402fab3be..787852ddfbd 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 56042551251..a2a14a006bb 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 getAllLocks(List tasks) { return tasks.stream()