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

Missing null check for Iterator.forEachRemaining implementations

    XMLWordPrintable

Details

    • b25
    • generic
    • generic
    • Verified

    Description

      A DESCRIPTION OF THE PROBLEM :
      Collections.unmodifiableMap(map).entrySet().iterator().forEachRemaining(action) and Collections.checkedMap(map, keyType, valueType).entrySet().iterator().forEachRemaining(action) are both missing a null check for the action. They wrap the possibly action in a new action, then delegate to the backing iterator. The delegate's null check passes, and the iteration consumes an element before a NullPointerException is thrown by the wrapping action when it tries to invoke the given action.

      Both methods should include a null check. In case of the unmodifiable map, the null check can probably be integrated into the entryConsumer method, instead of adding it before calling entryConsumer (which is now done in 3 of the 4 cases).

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Call Collections.unmodifiableMap(Map.of()).entrySet().iterator().forEachRemaining(null) and Collections.checkedMap(Map.of(), String.class, String.class).entrySet().iterator().forEachRemaining(null).

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      A NullPointerException is thrown.
      ACTUAL -
      Nothing is thrown.

      FREQUENCY : always


      Attachments

        Issue Links

          Activity

            People

              jpai Jaikiran Pai
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: