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

Can not print stack trace of StackOverflowError within a CompletableFuture

XMLWordPrintable

      ADDITIONAL SYSTEM INFORMATION :
      Happened in other OS's as well.

      A DESCRIPTION OF THE PROBLEM :
      When we get a stack overflow error within a CompletableFuture whenComplete, we can not print it's stack trace, print its message or even check it's type.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the attached code.




      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      We should see the stack overflow or to see all the numbers (i.e. 3,000).
      ACTUAL -
      The numbers stop at around 1,200-2,000. Sometimes we can see the "Got error" message, but never the stack (or the message).

      ---------- BEGIN SOURCE ----------
      import java.util.concurrent.CompletableFuture;

      public class OverflowInPromise
      {
          public static void main(String... args)
          {
              try
              {
                  Thread.setDefaultUncaughtExceptionHandler((t, e)->e.printStackTrace(System.out));

                  int size=3000;

                  var firstFuture=new CompletableFuture<Integer>();
                  var prevFuture=firstFuture;

                  for(int i=0; i<size; ++i)
                  {
                      var nextFuture=new CompletableFuture<Integer>();
                      prevFuture.whenComplete((j, e)->
                      {
                          try
                          {
                              if(e!=null)
                              {
                                  e.printStackTrace(System.out);
                              }
                              System.out.println("Completed "+j);
                              nextFuture.complete(j+1);
                          }
                          catch(Throwable t)
                          {
                              System.out.println("Got error");
                              t.printStackTrace(System.out);
                          }
                      });
                      prevFuture=nextFuture;
                  }

                  System.out.println(firstFuture.complete(1));

                  System.out.println(firstFuture.join());

              }
              catch(Throwable e)
              {
                  System.out.println("Ooops");
                  e.printStackTrace(System.out);
              }
          }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      Kotlin fibres?

      FREQUENCY : always


            martin Martin Buchholz
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: