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

j.u.Collections.emptyList() is inconsistent in not supporting the "set" operation via set(..) and replaceAll(..)

    XMLWordPrintable

Details

    Description

      Consider the following code sample:

      ---
              try {
                  Collections.emptyList().set(10, new Object());
              } catch (UnsupportedOperationException e) {
                  System.err.println("UnsupportedOperationException thrown, telling that the set operation is not supported by this list");
              }
              Collections.emptyList().replaceAll(e -> e);
      ---

      The output will be just

      UnsupportedOperationException thrown, telling that the set operation is not supported by this list



      On one hand empty list doesn't throw IndexOutOfBoundsException but throws UOE when calling set explicitly.

      On the other hand it allows to call replaceAll() operation.

      The following JCK tests will fail:

      api/java_util/Collections/empty/EmptyListReplaceAll.html#EmptyListReplaceAll[elementSettingNotSupported]
      api/java_util/Collections/empty/EMPTY_LISTReplaceAll.html#EMPTY_LISTReplaceAll[elementSettingNotSupported]
      api/java_util/Collections/empty/EMPTY_LISTReplaceAll.html#EMPTY_LISTReplaceAll[elementSettingNotSupported_passingNull]
      api/java_util/Collections/empty/EmptyListReplaceAll.html#EmptyListReplaceAll[elementSettingNotSupported_passingNull]




      Attachments

        Issue Links

          Activity

            People

              mduigou Mike Duigou
              dbessono Dmitry Bessonov
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: