Uploaded image for project: 'Commons Collections'
  1. Commons Collections
  2. COLLECTIONS-352

AbstractCollectionDecorator is inconsistent with AbstractListDecorator. Uses private member variable instead of protected getter

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 3.0, 3.1, 3.2
    • 4.0-alpha1, 4.0
    • Collection
    • None

    Description

      AbstractListDecorator uses getList() to access its private member variable for its methods:

          public int indexOf(Object object) {
              return getList().indexOf(object);
          }
      

      Which allows me to almost do something like this (notice I'm taking some liberties here with the no-arg serialization constructor):

          public static class FutureList<T> extends AbstractListDecorator {
      
              private Future<List<T>> futureList;
      
              public FutureList(Future<List<T>> futureList)
              {
                  super();
                  this.futureList = futureList;
              }
      
              @Override
              protected Collection<T> getCollection()
              {
                  try
                  {
                      return futureList.get();
                  }
                  catch (InterruptedException e)
                  {
                      throw new RuntimeException(e);
                  }
                  catch (ExecutionException e)
                  {
                      throw new RuntimeException(e);
                  }
              }
          }
      

      But AbstractCollectionDecorator uses its private member variable

          public boolean add(Object object) {
              return collection.add(object);
          }
      

      When it should be IMHO:

          public boolean add(Object object) {
              return getCollection().add(object);
          }
      

      Of course most everybody has an armpit and an opinion

      Attachments

        Activity

          People

            Unassigned Unassigned
            agent Adam Gent
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: