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

Lambda changes overloads when it throws an exception

XMLWordPrintable

    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      Given two lambdas that invoke a statement and do not return a value, one lambda is being mapped to Runnable while the another is mapped to Supplier. The only difference between the two is that the latter throws an exception.

      I am expecting both lambdas to map to the same type.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run testcase

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      add(Runnable)
      add(Runnable)
      ACTUAL -
      add(Runnable)
      add(Supplier)

      ---------- BEGIN SOURCE ----------
      public class Bug
      {
      public static void add(Runnable runnable)
      {
      System.out.println("add(Runnable)");
      }

      public static void add(java.util.function.Supplier<Integer> supplier)
      {
      System.out.println("add(Supplier)");
      }

      public static void main(String[] args)
      {
      add(() -> System.out.println());
      add(() ->
      {
      System.out.println();
      throw new RuntimeException();
      });
      }
      }
      ---------- END SOURCE ----------

      FREQUENCY : always


            vromero Vicente Arturo Romero Zaldivar
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: