add test and check for negative argument to HashMap::newHashMap et al

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: P4
    • 20
    • Affects Version/s: 20
    • Component/s: core-libs
    • None

      HashMap::newHashMap and related methods, added by JDK-8186958, specify that a negative argument will throw IllegalArgumentException. This occurs today, because a negative argument will be passed through calculateHashMapCapacity and then to a constructor, which will throw IAE. However, it seems unwise to rely on calculateHashMapCapacity always to provide a negative result if given a negative argument. (Indeed, some of the alternative implementations of this method returned a positive result given a negative argument.)

      Thus it seems prudent to add a test that ensures that the new HashMap-related static factory methods always throw IAE when given a negative argument, and further, checks should be added in the method implementations to break the reliance on this specific behavior of calculateHashMapCapacity.

            Assignee:
            Jaikiran Pai
            Reporter:
            Stuart Marks
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: