Uploaded image for project: 'MyFaces Trinidad'
  1. MyFaces Trinidad
  2. TRINIDAD-1251

Work-around buggy implementation of Collections.checkedList(), Collections.synchronizedList(), Collections.unmodifiableList()


    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.2.9-core, 1.2.10-core
    • Fix Version/s: 1.2.10-core
    • Component/s: None
    • Labels:
    • Environment:


      CollectionUtils.getSerializableList() attempt to optimize its behavior by only wrapping the List if the passed in backing List does not implement Serializable. However, Collections.checkedList(), Collections.synchronizedList(), Collections.unmodifiableList() are all implemented incorrectly with regard to Serialization. The implementation classes used always implement Serializable regardless of whether the supplied backing List is itself Serializable. This results in CollectionUtils.getSerializableList() not attempting to wrap the resulting List and thus Serialization errors.

      Two solutions are provided:

      1) A new function that always wraps is now provided:


      • Returns a List based on the passed in List <code>l</code>,
      • guaranteed to be Serializable. List <code>l</code> will be
      • wrapped in a List that implements Serializable and upon
      • Serialization the contents of <code>l</code> will be copied into
      • the result.
      • <p>
      • If <code>l</code> implements RandomAccess, any returned List will also
      • implement RandomAccess.
      • <p>
      • The results is very similar to creating a new ArrayList with the
      • contents of <code>l</code>, but no wrapper is created unless necessary
      • and the actual creation of the Serializable copy is deferred until
      • Serialization occurs.
      • <p>
      • Code that calls List.subList() and needs the result to be Serializable should always
      • use <code>newSerializableList</code> rather than <code>getSerializableList</code> because
      • the <code>java.util.Collections</code> implementations of <code>checkedList</code>,
      • <code>unmodifiableList</code>, and <code>synchronizedList</code> all lie and always implement
      • Serializable, regardless of the serializability of their backing List.
      • @param l The List to get a Serializable version of
      • @return A Serializable version of List <code>l</code>
      • @see #getSerializableList
      • @see #getSerializableCollection
        public static <T> List<T> newSerializableList(List<T> l)

      2) The implementation of public static <T> List<T> getSerializableList(List<T> l) has been changed to always wrap the result if the backing list was generated by Collections.checkedList(), Collections.synchronizedList() or Collections.unmodifiableList()

      In addition, the previous calls to Collectionutils.getSerializableList() are changed to CollectionUtils.newSerializableList() and the support for whitespace between the commas was removed, since it won't work when the System property is specified on the command line




            • Assignee:
              matzew Matthias We├čendorf
              btsulliv Blake Sullivan
            • Votes:
              0 Vote for this issue
              0 Start watching this issue


              • Created:

                Time Tracking

                Original Estimate - 2h
                Remaining Estimate - 2h
                Time Spent - Not Specified
                Not Specified