From 8733d5f9ed3062e27bfcd9a9f0fc4a92339d43d1 Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Fri, 24 Jan 2020 01:37:45 +0300 Subject: [PATCH] ArrayDeque: avoid triggering JDK 1.6 bug in tests Use System.arraycopy instead of Arrays.copyOfRange to avoid triggering JDK-7174363 bug in copyOfRange. Fix package of ArrayDequeTest --- .../stdlib/src/kotlin/collections/ArrayDeque.kt | 15 ++++++++++----- .../stdlib/test/collections/ArrayDequeTest.kt | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/libraries/stdlib/src/kotlin/collections/ArrayDeque.kt b/libraries/stdlib/src/kotlin/collections/ArrayDeque.kt index 786320c6bc9..b823a0f87e2 100644 --- a/libraries/stdlib/src/kotlin/collections/ArrayDeque.kt +++ b/libraries/stdlib/src/kotlin/collections/ArrayDeque.kt @@ -550,12 +550,17 @@ public class ArrayDeque : AbstractMutableList { if (isEmpty()) { structure(head, emptyArray()) - } else if (head < tail) { - @Suppress("UNCHECKED_CAST") - structure(head, elementData.sliceArray(head until tail)) + return + } + + val elements = arrayOfNulls(size) + if (head < tail) { + elementData.copyInto(elements, startIndex = head, endIndex = tail) + structure(head, elements) } else { - @Suppress("UNCHECKED_CAST") - structure(head - elementData.size, elementData.sliceArray(head until elementData.size).plus(elements = elementData.sliceArray(0 until tail))) + elementData.copyInto(elements, startIndex = head) + elementData.copyInto(elements, elementData.size - head, startIndex = 0, endIndex = tail) + structure(head - elementData.size, elements) } } } \ No newline at end of file diff --git a/libraries/stdlib/test/collections/ArrayDequeTest.kt b/libraries/stdlib/test/collections/ArrayDequeTest.kt index 4a67147b823..12244151e9b 100644 --- a/libraries/stdlib/test/collections/ArrayDequeTest.kt +++ b/libraries/stdlib/test/collections/ArrayDequeTest.kt @@ -3,7 +3,7 @@ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ -package collections +package test.collections import test.collections.behaviors.iteratorBehavior import test.collections.behaviors.listIteratorBehavior