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

Eager evaluation of lambda method reference

    XMLWordPrintable

Details

    • x86_64
    • windows_10

    Description

      ADDITIONAL SYSTEM INFORMATION :
      jdk 1.8.0_202-b08

      A DESCRIPTION OF THE PROBLEM :
      in my functioin, lambda method reference is argument, i think it is only a expression, but lamba method reference is calculating, let us see detail

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      public static boolean contains(List list, Object o) {
              return execute(list, o, l -> false, list::contains);
         }

       public static <R> R execute(List list, Object o,
                                      Function<Object, R> defaultConsumer,
                                      Function<Object, R> executeConsumer) {
              if (CollectionUtils.isEmpty(list) || null == o) {
                  return defaultConsumer.apply(list);
              }

           return executeConsumer.apply(o);
          
      }

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      when list is null , result Expected is false
      ACTUAL -
      but throw a NPE (list:contains)

      ---------- BEGIN SOURCE ----------
      public static boolean contains(List list, Object o) {
              return execute(list, o, l -> false, list::contains);
         }

       public static <R> R execute(List list, Object o,
                                      Function<Object, R> defaultConsumer,
                                      Function<Object, R> executeConsumer) {
              if (CollectionUtils.isEmpty(list) || null == o) {
                  return defaultConsumer.apply(list);
              }

           return executeConsumer.apply(o);
          
      }
      ---------- END SOURCE ----------

      FREQUENCY : always


      Attachments

        Activity

          People

            forax RĂ©mi Forax
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: