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

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

    XMLWordPrintable

Details

    • Bug
    • Status: Resolved
    • P4
    • Resolution: Fixed
    • 20
    • 20
    • core-libs
    • None

    Description

      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.

      Attachments

        Issue Links

          Activity

            People

              jpai Jaikiran Pai
              smarks Stuart Marks
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: