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

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 3.0, 3.1, 3.2
    • Fix Version/s: 4.0-alpha1, 4.0
    • Component/s: Collection
    • Labels:
      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

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

              Dates

              • Created:
                Updated:
                Resolved: