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

[jira] [Commented] (PROTON-1958) compareTo for tasks with same deadline is broken

    [ https://issues.apache.org/jira/browse/PROTON-1958?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16651780#comment-16651780 ] 

ASF GitHub Bot commented on PROTON-1958:
----------------------------------------

Github user gemmellr commented on the issue:

    https://github.com/apache/qpid-proton-j/pull/19
  
    I'll merge this later, could perhaps do with a test.
    
    Note that the example change should really have been kept separate as it has nothing to do with the defect (and as noted before, wont really make any difference to the example since it will typically only have 1 instance)


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