History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: QUARTZ-170
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: James House
Reporter: Bill Liu
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Quartz Scheduler

TriggerComparator compare() bug

Created: 07/Apr/05 06:32 PM   Updated: 07/Apr/05 11:07 PM
Component/s: None
Affects Version/s: None
Fix Version/s: 1.4.5


 Description  « Hide
If two triggers have the same next fire time, we compare the hashcode of the trigger. However, trig1.trigger.hashCode() - trig2.trigger.hashCode() does not work sometimes! In my test I have one trigger's hash code a negative interger. the result of a negative hash code (-2014330822 in my case, very close to the min value of an int) - positive hash code (889966298) is a negative number, and this number, unfortunately, is smaller than the minimum (-2147483648) allowed for an integer. Therefore, it's overflowed and becomes a positive number! The result? the sorting of timedTriggers are screwed up and it keeps getting the firstTrigger (as it can never remove it: timeTriggers.contains(timeTriggers.first()) always returns false!!).

I did not know I could get a negative hash code.

If you need further info, please email me.

Here is my improved version of the method:

public int compare(Object obj1, Object obj2) {
    TriggerWrapper trig1 = (TriggerWrapper) obj1;
    TriggerWrapper trig2 = (TriggerWrapper) obj2;

int comp = trig1.trigger.compareTo(trig2.trigger);//compare the next fire time.

if (comp == 0) {
      long value = (long)trig1.trigger.hashCode() - (long)trig2.trigger.hashCode();
      if(value > 0) {
        return 1;
      }
      else if (value == 0) {
        return 0;
      }
      else {
        return -1;
      }
    }
    return comp;
  }

 All   Comments   Change History      Sort Order:
James House - [07/Apr/05 11:07 PM ]
This bug was already fixed in Quartz 1.4.5