From aeb846527360a2c455836f3144061f632d053409 Mon Sep 17 00:00:00 2001 From: Boulay Mathias Date: Fri, 25 Aug 2023 00:26:25 +0200 Subject: [PATCH] Workaound[Collections]: allow legacy sort api of Collections --- patches/jdk8u_android.diff | 50 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/patches/jdk8u_android.diff b/patches/jdk8u_android.diff index f21c694..3fcd96c 100644 --- a/patches/jdk8u_android.diff +++ b/patches/jdk8u_android.diff @@ -60892,3 +60892,53 @@ index 303c96d788..aa555cc286 100644 + } + /** + +diff --git a/jdk/src/share/classes/java/util/Collections.java b/jdk/src/share/classes/java/util/Collections.java +index 3ab4c5ec06..768854e005 100644 +--- a/jdk/src/share/classes/java/util/Collections.java ++++ b/jdk/src/share/classes/java/util/Collections.java +@@ -111,2 +111,14 @@ public class Collections { + ++ /** ++ * Old sort allocation implementation can be selected (for ++ * compatibility with broken iterators) using a system property. ++ * This behavior was changed with JDK8_u20 ++ */ ++ public static final class LegacyAllocationSort { ++ private static final boolean userRequested = ++ java.security.AccessController.doPrivileged( ++ new sun.security.action.GetBooleanAction( ++ "java.util.Arrays.useLegacyCollectionsListSort")).booleanValue(); ++ } ++ + /** +@@ -142,3 +154,13 @@ public class Collections { + public static > void sort(List list) { +- list.sort(null); ++ if(LegacyAllocationSort.userRequested) { ++ Object[] a = list.toArray(); ++ Arrays.sort(a); ++ ListIterator i = list.listIterator(); ++ for (int j=0; j void sort(List list, Comparator c) { +- list.sort(c); ++ if(LegacyAllocationSort.userRequested) { ++ Object[] a = list.toArray(); ++ Arrays.sort(a, (Comparator)c); ++ ListIterator i = list.listIterator(); ++ for (int j=0; j