JDK-8288630 : Make Executable.getParameterCount() actually abstract
  • Type: CSR
  • Component: core-libs
  • Sub-Component: java.lang:reflect
  • Priority: P4
  • Status: Closed
  • Resolution: Approved
  • Fix Versions: 20
  • Submitted: 2022-06-16
  • Updated: 2022-06-17
  • Resolved: 2022-06-17
Related Reports
CSR :  
Description
Summary
-------

Change `Executable.getParameterCount` to be declared to be an `abstract` method, matching its semantics.

Problem
-------

While  `Executable.getParameterCount` is conceptually an abstract method, it is not coded as such, which is confusing. Since `Executable` is now `sealed`, only the implementation in `Mehtod` and `Constructor` are relevant.

Solution
--------
Change the method to be declared as `abstract`.

Specification
-------------

    --- a/src/java.base/share/classes/java/lang/reflect/Executable.java
    +++ b/src/java.base/share/classes/java/lang/reflect/Executable.java
    @@ -253,9 +253,7 @@ public abstract sealed class Executable extends AccessibleObject
          * @return The number of formal parameters for the executable this
          * object represents
          */
    -    public int getParameterCount() {
    -        throw new AbstractMethodError();
    -    }
    +    public abstract int getParameterCount();
     
         /**


Comments
Moving to Approved.
17-06-2022

JDK-8004729 added getParameterCount in Java 8. Maybe it wasn't recognized at the time that Executable was new in Java 8 and it could have been added as an abstract method? In any case, the change proposed is okay and not a compatibility issue as the class cannot be extended outside of the j.l.reflect.
17-06-2022