FoldCaseComparator should implement Serializable

XMLWordPrintable

    • Type: Bug
    • Resolution: Unresolved
    • Priority: P4
    • tbd
    • Affects Version/s: 26
    • Component/s: core-libs
    • None

      In open/src/java.base/share/classes/java/lang/String.java, the UNICODE_CASEFOLD_ORDER comparator is exposed as a public static field, but its implementing class (FoldCaseComparator) does not implement Serializable. This prevents collections or objects using the comparator from being serialized, leading to NotSerializableException at runtime. For example the following code will throw it:

              TreeSet<String> set = new TreeSet<>(UNICODE_CASEFOLD_ORDER);
              set.add("Foo");
              set.add("bar");

              try (ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("test.ser"))) {
                  out.writeObject(set);
              }




      The comparator may implement Serializable to align with CaseInsensitiveComparator.

            Assignee:
            Xueming Shen
            Reporter:
            Fernando Guallini
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: