Uploaded image for project: 'Application Server 3  4  5 and 6'
  1. Application Server 3 4 5 and 6
  2. JBAS-2797

org.jboss.varia.schedule.ScheduleManager iteration over of Hashtable values produces ClassCastExceptions

    XMLWordPrintable

Details

    Description

      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();
      ...

      Attachments

        Issue Links

          Activity

            People

              dandread1@redhat.com Dimitrios Andreadis
              jdoble_jira Jim Doble (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: