[
https://issues.apache.org/jira/browse/PROTON-1958?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Robbie Gemmell updated PROTON-1958:
-----------------------------------
Summary: compareTo for tasks with same deadline is broken (was: Equality
in TaskImpl is potentially broken (all instances have the same this.counter
value))
> compareTo for tasks with same deadline is broken
> ------------------------------------------------
>
> Key: PROTON-1958
> URL: https://issues.apache.org/jira/browse/PROTON-1958
> Project: Qpid Proton
> Issue Type: Bug
> Components: proton-j
> Affects Versions: proton-j-0.29.0
> Reporter: Jiri Daněk
> Priority: Major
>
> Looking at the implementation, it seems that every instance of TaskImpl has
> {{this.counter == 0}}. This seems wrong. The {{count}} field should be static
> for the instance id to work.
> {code}
> public class TaskImpl implements Task, Comparable<TaskImpl> {
> [...]
> private final AtomicInteger count = new AtomicInteger();
> [...]
> public TaskImpl(long deadline) {
> this.deadline = deadline;
> this.counter = count.getAndIncrement();
> }
> @Override
> public int compareTo(TaskImpl other) {
> int result;
> if (deadline < other.deadline) {
> result = -1;
> } else if (deadline > other.deadline) {
> result = 1;
> } else {
> result = counter - other.counter;
> }
> return result;
> }
> {code}
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]