DataBuffer constructors and methods do not specify required exceptions

XMLWordPrintable

    • 2d

      The specification for java.awt.image.DataBufferUShort does not clearly define the exceptions that may be thrown by several constructors and methods, leading to unspecified behavior.

      Constructors

      As and example the following constructors do not specify the exceptions they may throw for invalid inputs:

      DataBufferUShort(short[][] dataArray, int size)

      DataBufferUShort(short[][] dataArray, int size, int[] offsets)

      These constructors should explicitly specify that a NullPointerException is thrown when dataArray is null for example.

      Additionally, the constructor:

      DataBufferUShort(int size, int numBanks)

      does not specify the behavior when negative/OutOfBounds values are passed for size or numBanks. It is unclear whether a NegativeArraySizeException or an ArrayIndexOutOfBoundsException is expected in such cases.

      Methods

      For the following methods:

      getElem(...)

      getData(...)

      setElem(...)

      Here's a small standalone case that represents the issue ...

      void main() {
          DataBufferUShort db = new DataBufferUShort(4, 1);

          db.getElem(1, 0);
          db.getElem(0, 4);
          // similarly setElem(...) and getData(...)
      }

      Results:

      // ArrayIndexOutOfBoundsException is thrown
      // ArrayIndexOutOfBoundsException is thrown

            Assignee:
            Philip Race
            Reporter:
            Hamza Nassour
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated: