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

AbstractMap unnecessarily initializes two volatiles to null

    Details

    • Type: Enhancement
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 8
    • Fix Version/s: 9
    • Component/s: core-libs
    • Labels:

      Backports

        Description

        In AbstractMap there are two volatile fields that are explicitly set to null as part of initialization.
        This should be unnecessary since all fields are guaranteed to be null.

        public abstract class AbstractMap<K,V> implements Map<K,V> {
        ...
            /**
             * Each of these fields are initialized to contain an instance of the
             * appropriate view the first time this view is requested. The views are
             * stateless, so there's no reason to create more than one of each.
             */
            transient volatile Set<K> keySet = null;
            transient volatile Collection<V> values = null;
        ...
        }


        There might be other similar instance in the JDK that could be fixed at the same time.

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  mduigou Michael Duigou
                  Reporter:
                  sfriberg Staffan Friberg (Inactive)
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  8 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: