0 Replies Latest reply on Feb 7, 2006 2:27 PM by jdoble

    ScheduleManager Bug

    jdoble

      This may not be a good posting for "Beginners Corner", but I sure wasn't able to find another forum that seemed like a good fit. Here goes.

      We are using the org.jboss.varia.scheduler.ScheduleManager class, and have been getting ClassCastExceptions. Looking at the code, I can see why. There are a number of places where there is code like this:

      Iterator i = mSchedules.entrySet().iterator();
      while (i.hasNext()) {
       ScheduleInstance lInstance = (ScheduleInstance) i.next();
       ...
      

      Unless the mSchedules map is empty, this code is going to throw a ClassCastException every time, because the entrySet method on a Map produces a set of Map.Entry objects. The code should say something line the following instead:
      Iterator i = mSchedules.values().iterator();
      while (i.hasNext()) {
       ScheduleInstance lInstance = (ScheduleInstance) i.next();
       ...
      

      If you need the key and the value, you would do something like:
      Iterator i = mSchedules.entrySet().iterator();
      while (i.hasNext()) {
       Map.Entry entry = (Map.Entry) i.next();
       Integer id = (Integer) entry.getKey();
       ScheduleInstance lInstance = (ScheduleInstance) entry.getValue();
       ...
      

      I would be happy to submit a bug report, if someone could (politely) point me to the right place to do so.