From c5bc741fb8171306e443ab187b32c4ff708c22d0 Mon Sep 17 00:00:00 2001 From: Abel Del Pino Date: Wed, 10 Jul 2024 13:42:05 -0700 Subject: [PATCH] Fix removeX callsites (4/N) Summary: Because of a Kotlin bug with JDK21 when using SDK 35, removeFirst() and removeLast() cause a runtime `NoSuchMethodError` when called with a MutableList, List or ArrayList. So fixing these callsites before the SDK 35 upgrade Reviewed By: jselbo Differential Revision: D59592734 fbshipit-source-id: 33c5a253917143c59ee9315f2f1a60c4fd88ea60 --- .../flipper/plugins/uidebugger/core/AttributeEditor.kt | 3 ++- .../com/facebook/flipper/plugins/uidebugger/core/BitmapPool.kt | 3 ++- .../flipper/plugins/uidebugger/core/LayoutTraversal.kt | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/android/src/main/java/com/facebook/flipper/plugins/uidebugger/core/AttributeEditor.kt b/android/src/main/java/com/facebook/flipper/plugins/uidebugger/core/AttributeEditor.kt index 48c9751060e..9cb5074bdbb 100644 --- a/android/src/main/java/com/facebook/flipper/plugins/uidebugger/core/AttributeEditor.kt +++ b/android/src/main/java/com/facebook/flipper/plugins/uidebugger/core/AttributeEditor.kt @@ -54,7 +54,8 @@ class AttributeEditor( val stack = mutableListOf(applicationRef) while (stack.isNotEmpty()) { - val curNode = stack.removeLast() + // Workaround for a JDK21/Kotlin bug, see KT-66044 + val curNode = checkNotNull(stack.removeLastOrNull()) val curDescriptor = descriptorRegister.descriptorForClassUnsafe(curNode.javaClass) if (curDescriptor.getId(curNode) == nodeId) { return curNode diff --git a/android/src/main/java/com/facebook/flipper/plugins/uidebugger/core/BitmapPool.kt b/android/src/main/java/com/facebook/flipper/plugins/uidebugger/core/BitmapPool.kt index 7d2dd19b830..560b6d85520 100644 --- a/android/src/main/java/com/facebook/flipper/plugins/uidebugger/core/BitmapPool.kt +++ b/android/src/main/java/com/facebook/flipper/plugins/uidebugger/core/BitmapPool.kt @@ -48,7 +48,8 @@ class BitmapPool(private val config: Bitmap.Config = Bitmap.Config.RGB_565) { return if (bitmaps == null || bitmaps.isEmpty()) { LeasedBitmap(Bitmap.createBitmap(width, height, config)) } else { - LeasedBitmap(bitmaps.removeLast()) + // Workaround for a JDK21/Kotlin bug, see KT-66044 + LeasedBitmap(checkNotNull(bitmaps.removeLastOrNull())) } } diff --git a/android/src/main/java/com/facebook/flipper/plugins/uidebugger/core/LayoutTraversal.kt b/android/src/main/java/com/facebook/flipper/plugins/uidebugger/core/LayoutTraversal.kt index 1361ca17190..8af64610b4a 100644 --- a/android/src/main/java/com/facebook/flipper/plugins/uidebugger/core/LayoutTraversal.kt +++ b/android/src/main/java/com/facebook/flipper/plugins/uidebugger/core/LayoutTraversal.kt @@ -41,7 +41,8 @@ class LayoutTraversal( val shallow = mutableSetOf() while (stack.isNotEmpty()) { - val (node, parentId) = stack.removeLast() + // Workaround for a JDK21/Kotlin bug, see KT-66044 + val (node, parentId) = checkNotNull(stack.removeLastOrNull()) try {