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

getDeclaredMethod and getDeclaredMethods results have different 'throws' clause

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • 25
    • 21
    • 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] { }

            darcy Joe Darcy
            cushon Liam Miller-Cushon
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: