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

Use `List.of()` in Locale.LanguageTag.EMPTY_SUBTAGS for CDS

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • tbd
    • 26
    • core-libs

      JDK-8357281 utilizes `Collections.emptyList()` for the static final field EMPTY_TAGS. However, this implementation causes issues for CDS archive and a swap to `List.of()` is preferable as it has no static fields and resolves the error.


      Comment copied from JDK-8357281

      There's a report by "Thihup" using "cds" reading:
      ```
      [1.367s][warning][aot,heap] Archive heap points to a static field that may hold a different value at runtime:
      [1.367s][warning][aot,heap] Field: sun/util/locale/LanguageTag::EMPTY_SUBTAGS
      [1.368s][warning][aot,heap] Value: java.util.Collections$EmptyList
      [1.369s][warning][aot,heap] {0x00000000cb006f68} - klass: 'java/util/Collections$EmptyList' - flags:
      [1.369s][warning][aot,heap]
      [1.370s][warning][aot,heap] - ---- fields (total size 2 words):
      [1.371s][warning][aot,heap] - protected transient 'modCount' 'I' @8 0 (0x00000000)
      [1.371s][warning][aot,heap] --- trace begin ---
      [1.371s][warning][aot,heap] [ 0] {0x00000000cb006f68} java.util.Collections$EmptyList
      [1.371s][warning][aot,heap] --- trace end ---
      [1.371s][warning][aot,heap]
      [1.372s][error ][aot,heap] Scanned 38492 objects. Found 1 case(s) where an object points to a static field that may hold a different value at runtime.
      [1.372s][error ][aot,heap] Please see cdsHeapVerifier.cpp and aotClassInitializer.cpp for details
      [1.372s][error ][cds ] An error has occurred while writing the shared archive file.
      ```

      With `List.of()` instead of `Collections.emptyList()` that error could be avoided: no static fields in their class(es) implementation(s).

            jlu Justin Lu
            jlu Justin Lu
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: