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

ModuleLayer::parents should return an unmodifiable list

    Details

    • Type: CSR
    • Status: Closed
    • Priority: P3
    • Resolution: Approved
    • Fix Version/s: 15
    • Component/s: core-libs
    • Labels:
      None
    • Subcomponent:
    • Compatibility Kind:
      behavioral
    • Compatibility Risk:
      low
    • Compatibility Risk Description:
      It is unlikely that there is anything that assumes they can modify the list of parents. We don't plan to create a release note for this at this time.
    • Interface Kind:
      Java API
    • Scope:
      SE

      Description

      Summary

      java.lang.ModuleLayer::parents needs to specify that it returns an unmodifiable list of module layers.

      Problem

      This is an oversight in the original specification and implementation. Module layers are immutable, the list returned by the parents() method should be an unmodifiable list. The equivalent parents() method in java.lang.module.Configuration correctly specifies that the list is unmodifiable. The set of modules returned by ModuleLayer::modules and Configuration::modules also specify that the sets are unmodifable.

      Solution

      Change the specification of ModuleLayer::parents to specify that the list is unmodifiable.

      Update the implementation to return an unmodifiable list. The compatibility impact of changing the implementation is minimal, nothing could rely on being able to modify the list.

      Specification

      Change the specification for ModuleLayer::parents to specify that it returns an unmodifiable list:

           /**
      -     * Returns the list of this layer's parents unless this is the
      -     * {@linkplain #empty empty layer}, which has no parents and so an
      +     * Returns an unmodifiable list of this layer's parents, in search
      +     * order. If this is the {@linkplain #empty() empty layer} then an
            * empty list is returned.
            *
      -     * @return The list of this layer's parents
      +     * @return A possibly-empty unmodifiable list of this layer's parents
            */

      Adjust the specification for ModuleLayer::modules to make it clearer that it returns an unmodifiable set (this does not introduce any testable assertions because the @return also specifies that it returns an unmodifiable set.

           /**
      -     * Returns the set of the modules in this layer.
      +     * Returns an unmodifiable set of the modules in this layer.
            *
            * @return A possibly-empty unmodifiable set of the modules in this layer
            */

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                alanb Alan Bateman
                Reporter:
                alanb Alan Bateman
                Reviewed By:
                Mandy Chung, Mark Reinhold
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: