getDeclaredMethod and getDeclaredMethods results have different 'throws' clause

XMLWordPrintable

    • Type: Bug
    • Resolution: Not an Issue
    • Priority: P4
    • 25
    • Affects Version/s: 21
    • Component/s: core-libs
    • None

      The Method returned for resolveConstantDesc on java.lang.String has a different list of thrown exceptions depending on which of getDeclaredMethod and getDeclaredMethods and was used to access it.

      $ java -fullversion
      openjdk full version "20-ea+35-2342"

      jshell> var a = Arrays.stream(String.class.getDeclaredMethods()).filter(x -> x.getName().contentEquals("resolveConstantDesc")).findAny().get()
      jshell> var b = String.class.getDeclaredMethod("resolveConstantDesc", java.lang.invoke.MethodHandles.Lookup.class)

      jshell> a
      a ==> public java.lang.Object java.lang.String.resolveConstantDesc(java.lang.invoke.MethodHandles$Lookup) throws java.lang.ReflectiveOperationException
      jshell> a.getExceptionTypes()
      $16 ==> Class[1] { class java.lang.ReflectiveOperationException }

      jshell> b
      b ==> public java.lang.String java.lang.String.resolveConstantDesc(java.lang.invoke.MethodHandles$Lookup)
      jshell> b.getExceptionTypes()
      $18 ==> Class[0] { }

            Assignee:
            Joe Darcy
            Reporter:
            Liam Miller-Cushon
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: