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

Collections.checkedMap Map.merge does not properly check key and value

    XMLWordPrintable

Details

    Description

      A DESCRIPTION OF THE PROBLEM :
      The `Map.merge` method of the map created by `Collections.checkedMap` (and related factory methods) does not check the key and value type when no entry exists yet.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the code provided below

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The `merge` call should fail with a ClassCastException because both the key and value type are incorrect.
      ACTUAL -
      No exception is thrown and the invalid key and value are added to the map.

      ---------- BEGIN SOURCE ----------
      Map m = Collections.checkedMap(new HashMap<>(), Integer.class, Integer.class);
      m.merge("key", "value", (v1, v2) -> null);

      ---------- END SOURCE ----------

      FREQUENCY : always


      Attachments

        Issue Links

          Activity

            People

              smarks Stuart Marks
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated: