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

java.lang.invoke.LambdaConversionException: Invalid receiver type ...

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b93
    • CPU:
      x86_64
    • OS:
      windows_7
    • Verification:
      Verified

      Backports

        Description

        FULL PRODUCT VERSION :
        java version "1.8.0_60"
        Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
        Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)

        ADDITIONAL OS VERSION INFORMATION :
        Microsoft Windows [Version 6.1.7601]

        A DESCRIPTION OF THE PROBLEM :
        At runtime I get a java.lang.BootstrapMethodError which is caused by a java.lang.invoke.LambdaConversionException

        Basically, I have a type T extends Enum<T> & Supplier<K>
        and then use a method reference which refers to the Supplier's "get" method, i.e. T::get

        Note: since this error occurs at run-time & involves java.lang.invoke, I filed the issue against java.lang, but it may well be that the actual issue is in the compiler.

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Compile and execute the attached test case

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        A single line of output
        ACTUAL -
        An exception is thrown

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------

        import java.time.LocalDate;
        import java.util.EnumSet;
        import java.util.Objects;
        import java.util.Optional;
        import java.util.function.Function;
        import java.util.function.Supplier;

        public class Issue {

        public static void main(String[] args) {
        System.out.println(valueOfKey(Size.class, LocalDate.now()));
        }

        enum Size implements Supplier<LocalDate> {
        S, M, L;

        @Override
        public LocalDate get() {
        return LocalDate.now();
        }

        }

        public static <K, T extends Enum<T> & Supplier<K>> Optional<T> valueOfKey(Class<T> enumType, K key) {
        return valueOf(enumType, key, T::get);
        }

        public static <K, T extends Enum<T>> Optional<T> valueOf(Class<T> enumType, K key, Function<T, K> keyExtractor) {
        return EnumSet.allOf(enumType)
        .stream()
        .filter(t -> Objects.equals(keyExtractor.apply(t), key))
        .findFirst();
        }

        }

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

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                sadayapalam Srikanth Adayapalam
                Reporter:
                webbuggrp Webbug Group
                Votes:
                0 Vote for this issue
                Watchers:
                6 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved: