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

Unnecessary reallocation when constructing WeakHashMap from a large Map

    Details

      Description

      The constructor WeakHashMap(Map<? extends K, ? extends V> m) delegates construction as
              this(Math.max((int) (m.size() / DEFAULT_LOAD_FACTOR) + 1,
                      DEFAULT_INITIAL_CAPACITY),
                   DEFAULT_LOAD_FACTOR);

      If m.size() is large (>= 1610612672) then the first argument of Math.max() becomes negative due to integer overflow, and WeakHashMap with default capacity is created.

      While it is mostly unnoticeable, it is unnecessary.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                igerasim Ivan Gerasimov
                Reporter:
                igerasim Ivan Gerasimov
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: