Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4647973

spec for Container.remove() incomplete

XMLWordPrintable

    • b95
    • generic, sparc
    • linux, solaris_2.6, solaris_7

      Name: atR10191 Date: 03/06/2002


      specification should define the behaviour of a call to
       Container.remove(int index) with an invalid index

      Current implementation can throw different exception under certain conditions.

      When the Container is instantiated, the default constructor creates a Container
      with a default array length of 4 null components.

      Hence, attempts to remove a component from the Container at index < 0 or > 3
      will result in an ArrayIndexOutOfBoundsException.

      Attempts to remove a component from the Container at index >= 0 or <= 3, will
      result in a NullPointerException if no component exists within that index of
      the component array.

      However, the exception thrown (if any) should be consistent across all
      implementations. Hence, it is not acceptable for the NullPointerException to be
      thrown as the RI has a default creation of an empty 4-element component array.
      Another implementation might create an empty 5-element array that would result
      in different behaviour with a different exception thrown.

      At present, the specification does not define this behaviour - indicating that
      the method should fail silently. Would it be more helpful to the user to have
      this behaviour defined in order to indicate where the error has occurred?

      With that in mind, should the specification document that this method can result
      in an unchecked runtime exception in the
      @throws tag of this method definition when called with an invalid index -
       eg. IllegalArgumentException.
      ======================================================================

            son Oleg Sukhodolsky (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: