diff --git a/src/java.base/share/classes/java/util/ArrayList.java b/src/java.base/share/classes/java/util/ArrayList.java index 5fcf79e95c3..bcf7b79e780 100644 --- a/src/java.base/share/classes/java/util/ArrayList.java +++ b/src/java.base/share/classes/java/util/ArrayList.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -1582,6 +1582,13 @@ public class ArrayList extends AbstractList } }; } + + @Override + public void sort(Comparator c) { + checkForComodification(); + root.sortRange(c, offset, offset + size); + updateSizeAndModCount(0); + } } /** @@ -1799,10 +1806,14 @@ public class ArrayList extends AbstractList } @Override - @SuppressWarnings("unchecked") public void sort(Comparator c) { + sortRange(c, 0, size); + } + + @SuppressWarnings("unchecked") + private void sortRange(Comparator c, int fromIndex, int toIndex) { final int expectedModCount = modCount; - Arrays.sort((E[]) elementData, 0, size, c); + Arrays.sort((E[]) elementData, fromIndex, toIndex, c); if (modCount != expectedModCount) throw new ConcurrentModificationException(); modCount++; diff --git a/test/jdk/java/util/List/ListDefaults.java b/test/jdk/java/util/List/ListDefaults.java index c29d2243f41..8c9e7e3f613 100644 --- a/test/jdk/java/util/List/ListDefaults.java +++ b/test/jdk/java/util/List/ListDefaults.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -50,7 +50,7 @@ import java.util.function.Predicate; /** * @test * @summary Unit tests for extension methods on List - * @bug 8023367 8037106 + * @bug 8023367 8037106 8325679 * @library ../Collection/testlibrary * @build CollectionAsserts CollectionSupplier ExtendsAbstractList * @run testng ListDefaults