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

XMLWordPrintable

    • Type: Bug
    • Resolution: Unresolved
    • Priority: P4
    • tbd
    • Affects Version/s: 11, 17, 19
    • Component/s: tools
    • None
    • generic
    • generic

      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

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

              Created:
              Updated: