Unnecessary reallocation when constructing WeakHashMap from a large Map

XMLWordPrintable

      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.

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

              Created:
              Updated:
              Resolved: