Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8332299

SwingWorker does not call done when it is cancelled before being scheduled

XMLWordPrintable

    • b12
    • 21
    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      When a SwingWorker is cancelled before the executor has picked it up for execution and calls its run() method, the done() method will never be called.

      This is a major behavior change in version 21 compared to prior releases, and is a side effect of the changes in commit dbb5581 that resolved JDK-8081474.

      REGRESSION : Last worked in version 17.0.11

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create a swing worker, pass it to the executor and cancel it immediately before the executor calls the run() method of the worker.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      done() is called as in version 20 and earlier.
      ACTUAL -
      done() is not called.

      ---------- BEGIN SOURCE ----------
      public class Main {

        private static class Worker extends SwingWorker {

          @Override
          protected Object doInBackground() throws Exception {
            return null;
          }
          
          @Override
          protected void done() {
            System.out.println("done called");
          }
        }
        
        public static void main(String... args) {
          Worker worker = new Worker();
          worker.execute();
          worker.cancel(false);
        }

      }

      ---------- END SOURCE ----------

      FREQUENCY : always


        1. Main.java
          0.4 kB
          Praveen Narayanaswamy

            psadhukhan Prasanta Sadhukhan
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: