Spec for j.util.Timer::purge and j.util.Timer::cancel could be improved

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: P4
    • 22
    • Affects Version/s: None
    • Component/s: core-libs
    • b23

      The spec for j.u.Timer::purge asserts:

      ================
      Removes all cancelled tasks from this timer's task queue.
      Calling this method has no effect on the behavior of the timer, but eliminates the references to the cancelled tasks from the queue.

      Returns:
      the number of tasks removed from the queue
      ================

      However the OpenJDK implementation seem to be not completely matching the spec and the following example

              Timer timer = new Timer();
              timer.schedule(new TimerTask() {
                  @Override public void run() { System.out.println("timer = " + timer); }
              }, 5000);
              timer.cancel();
              System.out.println("timer.purge() = " + timer.purge());


      prints

          timer.purge() = 0

      consistently


            Assignee:
            Justin Lu
            Reporter:
            Dmitry Bessonov
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: