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

Unsafe typecast in java.util.stream.SpinedBuffer

XMLWordPrintable

    • b112
    • Not verified

      Unsafe long to int typecast:

      public E get(long index) {
          ......
          return curChunk[((int) index)];
          ......
          return spine[j][((int) (index - priorElementCount[j]))];

      public E[] asArray(IntFunction<E[]> arrayFactory) {
          // @@@ will fail for size == MAX_VALUE
          E[] result = arrayFactory.apply((int) count());

      public T_ARR asPrimitiveArray() {
          // @@@ will fail for size == MAX_VALUE
          T_ARR result = newArray((int) count());

          static class OfInt extends SpinedBuffer.OfPrimitive<Integer, int[], IntConsumer>
              ........
              public int get(long index) {
                  int ch = chunkFor(index);
                  if (spineIndex == 0 && ch == 0)
                      return curChunk[(int) index];
                  else
                      return spine[ch][(int) (index-priorElementCount[ch])];
              }

      Same for:
          static class OfLong
          static class OfDouble

            psandoz Paul Sandoz
            ogb Oleg Barbashov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: