You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@qpid.apache.org by "Jiri Daněk (JIRA)" <ji...@apache.org> on 2018/10/16 10:44:00 UTC

[jira] [Created] (PROTON-1958) Equality in TaskImpl is potentially broken (all instances have the same this.counter value)

Jiri Daněk created PROTON-1958:
----------------------------------

             Summary: Equality in TaskImpl is potentially broken (all instances have the same this.counter value)
                 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


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: dev-unsubscribe@qpid.apache.org
For additional commands, e-mail: dev-help@qpid.apache.org