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

Javac ignores throws Throwable for Method References to MethodHandle::invoke

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P4
    • tbd
    • 11, 17, 19
    • tools
    • None
    • generic
    • generic

    Description

      Reproducer:

      import java.util.function.Supplier;
      import java.lang.invoke.MethodHandles;
      import java.lang.invoke.MethodType;

      class Scratch {
          public static void main(String[] args) {
              Supplier<Object> x = MethodHandles.zero(Object.class)::invoke;
          }
      }

      As MethodHandles.invoke is declared to throw Throwable, this code should not compile and fail with a 'unhandled exception Throwable'

      Javac compiles that code successfully, ignoring the throws Throwable.
      Tested with:
      8: error: incompatible thrown types Throwable in method reference (*This is the desired result*)
      11: compiles
      17: compiles
      19: compiles

      Attachments

        Activity

          People

            vromero Vicente Arturo Romero Zaldivar
            jkuhn Johannes Kuhn
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated: