JDK-8322969 : Including sealing information Class.toGenericString()
  • Type: CSR
  • Component: core-libs
  • Sub-Component: java.lang:reflect
  • Priority: P4
  • Status: Closed
  • Resolution: Approved
  • Fix Versions: 23
  • Submitted: 2024-01-03
  • Updated: 2024-01-03
  • Resolved: 2024-01-03
Related Reports
CSR :  
Description
Summary
-------
Include `sealed` conceptual modifier in the output of `Class.toGenericString()`.

Problem
-------

While appearing as a modifier in Java source, `sealed` is not included in the output of `Class.toGenericString()`, which tends to include more information than `Class.toString()`.

Solution
--------
Update the specification and implementation of `Class.toGenericString()` to include `sealed` information for a class or interface.

Note `non-sealed` is not directly represented in a class file and thus is _not_ output by `Class.toGenericString()`.

Consistent with omitted `implements` and `extends` information, the list of `permitted` classes/interfaces is omitted by `Class.toGenericString()`.

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

    diff --git a/src/java.base/share/classes/java/lang/Class.java b/src/java.base/share/classes/java/lang/Class.java
    index 851d65d06ad..2848cd008d0 100644
    --- a/src/java.base/share/classes/java/lang/Class.java
    +++ b/src/java.base/share/classes/java/lang/Class.java
    @@ -261,7 +261,7 @@ public String toString() {
     
         /**
          * Returns a string describing this {@code Class}, including
    -     * information about modifiers and type parameters.
    +     * information about modifiers, {@linkplain #isSealed() sealing}, and type parameters.
          *
          * The string is formatted as a list of type modifiers, if any,
          * followed by the kind of type (empty string for primitive types


Comments
Moving to Approved.
03-01-2024