JDK-8283434 : Update java.lang.invoke.MethodHandle to use sealed classes
  • Type: CSR
  • Component: core-libs
  • Sub-Component: java.lang:reflect
  • Priority: P4
  • Status: Closed
  • Resolution: Approved
  • Fix Versions: 19
  • Submitted: 2022-03-20
  • Updated: 2022-03-21
  • Resolved: 2022-03-21
Related Reports
CSR :  
Description
Summary
-------

Update `MethodHandle` to be a sealed class.

Problem
-------

The `MethodHandle` class is not intended to have user-defined subclasses and sealing is an explicit way to indicate this.

Solution
--------

Update the class to be declared 'sealed`. Other needed changes are implementation-only and not part of the user-visible API change listed in this CSR.

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

    --- a/src/java.base/share/classes/java/lang/invoke/MethodHandle.java
    +++ b/src/java.base/share/classes/java/lang/invoke/MethodHandle.java
    @@ -440,7 +440,9 @@ mh.invokeExact(System.out, "Hello, world.");
      * @author John Rose, JSR 292 EG
      * @since 1.7
      */
    -public abstract class MethodHandle implements Constable {
    +public abstract sealed class MethodHandle implements Constable
    +    permits NativeMethodHandle, DirectMethodHandle,
    +            DelegatingMethodHandle, BoundMethodHandle {
     
         /**
          * Internal marker interface which distinguishes (to the Java compiler)


Comments
Moving to Approved.
21-03-2022