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

Undefined NullPointerException in TreeBag.java

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 4.1
    • 4.1
    • Bag
    • None

    Description

      In add(final E object) method of TreeBag.java, the parameter object is not null-checked in throw IlligalArgumentException statement. Thus, it crashes with an inappropriate type of exceptions when the parameter, object is null. object can be null from the argument, transform(object) in TransformedCollection.add(final E object).
      I think object ==null should be added in the predicate of the throw IlligalArgumentException statement like below.

          public boolean add(final E object) {
              if((object==null) || (comparator() == null && !(object instanceof Comparable))) {
                  throw new IllegalArgumentException("Objects of type " + object.getClass() + " cannot be added to " +
                                                     "a naturally ordered TreeBag as it does not implement Comparable");
              }
              return super.add(object);
          }
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            mjkim0324 M Kim
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: