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

[8u] Use an internal listOf & setOf when backporting List.of & Set.of

XMLWordPrintable

      It is common in backporting changes from 11u+ to come across code which uses List.of or Set.of

      It is tempting to just replace these with new HashSet or new ArrayList (e.g. https://github.com/openjdk/jdk8u/pull/61/commits/53e8134702c5967ffd886b8530ee5728907cae91) but the *.of methods actually return unmodifiable sets and lists, while also performing null and duplicate checks on the arguments.

      For test code, we introduced internal versions of List.of and Set.of in the test library. As cases also occur in the JDK code (such as in the backport of 8337664, https://github.com/openjdk/jdk8u/pull/61) it is probably worth moving this into sun.misc or similar with the JDK library itself, so all backports can use it.

            andrew Andrew Hughes
            andrew Andrew Hughes
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: