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.
This commit is contained in:
Furkan KAMACI 2019-02-07 01:08:51 +03:00 committed by Clint Wylie
parent 315ccb76b8
commit 58f9507ccf
2 changed files with 34 additions and 7 deletions

View File

@ -1073,16 +1073,13 @@ public class TaskLockbox
return true; return true;
} }
if (!getClass().equals(o.getClass())) { if (o == null || !getClass().equals(o.getClass())) {
return false; return false;
} }
final TaskLockPosse that = (TaskLockPosse) o; TaskLockPosse that = (TaskLockPosse) o;
if (!taskLock.equals(that.taskLock)) { return java.util.Objects.equals(taskLock, that.taskLock) &&
return false; java.util.Objects.equals(taskIds, that.taskIds);
}
return taskIds.equals(that.taskIds);
} }
@Override @Override

View File

@ -667,6 +667,36 @@ public class TaskLockboxTest
Assert.assertTrue(lowLockPosse.getTaskLock().isRevoked()); 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) private Set<TaskLock> getAllLocks(List<Task> tasks)
{ {
return tasks.stream() return tasks.stream()