1 Reply Latest reply on Dec 3, 2002 1:25 PM by Juha Lindfors

    Timer updateTables

    Michael Steinle Newbie

      Removing a timer notification from a timer inside a timer's listener callback method results in a NullPointerException. The exception arises because the timer notification is deleted and removed from the timer notification inside the timer's listener callback, but is used in the updateTables method of the timer after finishing the timer's listener callback.

      The original code is the folling:
      private synchronized void updateTimerTable(Integer notifID) {

      Object[] obj = (Object[])timerTable.get(notifID);
      Date date = (Date)obj[TIMER_DATE_INDEX];
      Long period = (Long)obj[TIMER_PERIOD_INDEX];

      To avoid such a NullPointerException the code has to be changed to:

      private synchronized void updateTimerTable(Integer notifID) {

      Object[] obj = (Object[])timerTable.get(notifID);
      if (obj == null) return;
      Date date = (Date)obj[TIMER_DATE_INDEX];
      Long period = (Long)obj[TIMER_PERIOD_INDEX];