Description: Fixes the backward compatibility when running with Java 8
 When building with Java 17 the CharSequence.isEmpty() method is used instead of
 the extension method added to the CharSequence class by Kotlin. This causes
 NoSuchMethodErrors at runtime when Kotlin is used with Java 8.
Author: Emmanuel Bourg <ebourg@apache.org>
Forwarded: not-needed
Last-Update: 2023-02-01

--- a/core/metadata.jvm/src/org/jetbrains/kotlin/metadata/jvm/deserialization/utfEncoding.kt
+++ b/core/metadata.jvm/src/org/jetbrains/kotlin/metadata/jvm/deserialization/utfEncoding.kt
@@ -48,7 +48,7 @@
         }
     }
 
-    if (!buffer.isEmpty()) {
+    if (buffer.length != 0) {
         result.add(buffer.toString())
     }
 
--- a/libraries/stdlib/common/src/generated/_Strings.kt
+++ b/libraries/stdlib/common/src/generated/_Strings.kt
@@ -63,7 +63,7 @@
  * @throws [NoSuchElementException] if the char sequence is empty.
  */
 public fun CharSequence.first(): Char {
-    if (isEmpty())
+    if (length == 0)
         throw NoSuchElementException("Char sequence is empty.")
     return this[0]
 }
@@ -81,7 +81,7 @@
  * Returns the first character, or `null` if the char sequence is empty.
  */
 public fun CharSequence.firstOrNull(): Char? {
-    return if (isEmpty()) null else this[0]
+    return if (length == 0) null else this[0]
 }
 
 /**
@@ -136,7 +136,7 @@
  * @throws [NoSuchElementException] if the char sequence is empty.
  */
 public fun CharSequence.last(): Char {
-    if (isEmpty())
+    if (length == 0)
         throw NoSuchElementException("Char sequence is empty.")
     return this[lastIndex]
 }
@@ -157,7 +157,7 @@
  * Returns the last character, or `null` if the char sequence is empty.
  */
 public fun CharSequence.lastOrNull(): Char? {
-    return if (isEmpty()) null else this[length - 1]
+    return if (length == 0) null else this[length - 1]
 }
 
 /**
@@ -189,7 +189,7 @@
  */
 @SinceKotlin("1.3")
 public fun CharSequence.random(random: Random): Char {
-    if (isEmpty())
+    if (length == 0)
         throw NoSuchElementException("Char sequence is empty.")
     return get(random.nextInt(length))
 }
@@ -927,7 +927,7 @@
  * @sample samples.collections.Collections.Aggregates.any
  */
 public fun CharSequence.any(): Boolean {
-    return !isEmpty()
+    return length != 0
 }
 
 /**
@@ -1028,7 +1028,7 @@
  * Returns the largest character or `null` if there are no characters.
  */
 public fun CharSequence.max(): Char? {
-    if (isEmpty()) return null
+    if (length == 0) return null
     var max = this[0]
     for (i in 1..lastIndex) {
         val e = this[i]
@@ -1043,7 +1043,7 @@
  * @sample samples.collections.Collections.Aggregates.maxBy
  */
 public inline fun <R : Comparable<R>> CharSequence.maxBy(selector: (Char) -> R): Char? {
-    if (isEmpty()) return null
+    if (length == 0) return null
     var maxElem = this[0]
     var maxValue = selector(maxElem)
     for (i in 1..lastIndex) {
@@ -1061,7 +1061,7 @@
  * Returns the first character having the largest value according to the provided [comparator] or `null` if there are no characters.
  */
 public fun CharSequence.maxWith(comparator: Comparator<in Char>): Char? {
-    if (isEmpty()) return null
+    if (length == 0) return null
     var max = this[0]
     for (i in 1..lastIndex) {
         val e = this[i]
@@ -1074,7 +1074,7 @@
  * Returns the smallest character or `null` if there are no characters.
  */
 public fun CharSequence.min(): Char? {
-    if (isEmpty()) return null
+    if (length == 0) return null
     var min = this[0]
     for (i in 1..lastIndex) {
         val e = this[i]
@@ -1089,7 +1089,7 @@
  * @sample samples.collections.Collections.Aggregates.minBy
  */
 public inline fun <R : Comparable<R>> CharSequence.minBy(selector: (Char) -> R): Char? {
-    if (isEmpty()) return null
+    if (length == 0) return null
     var minElem = this[0]
     var minValue = selector(minElem)
     for (i in 1..lastIndex) {
@@ -1107,7 +1107,7 @@
  * Returns the first character having the smallest value according to the provided [comparator] or `null` if there are no characters.
  */
 public fun CharSequence.minWith(comparator: Comparator<in Char>): Char? {
-    if (isEmpty()) return null
+    if (length == 0) return null
     var min = this[0]
     for (i in 1..lastIndex) {
         val e = this[i]
@@ -1122,7 +1122,7 @@
  * @sample samples.collections.Collections.Aggregates.none
  */
 public fun CharSequence.none(): Boolean {
-    return isEmpty()
+    return length == 0
 }
 
 /**
@@ -1147,7 +1147,7 @@
  * Accumulates value starting with the first character and applying [operation] from left to right to current accumulator value and each character.
  */
 public inline fun CharSequence.reduce(operation: (acc: Char, Char) -> Char): Char {
-    if (isEmpty())
+    if (length == 0)
         throw UnsupportedOperationException("Empty char sequence can't be reduced.")
     var accumulator = this[0]
     for (index in 1..lastIndex) {
@@ -1163,7 +1163,7 @@
  * and the character itself and calculates the next accumulator value.
  */
 public inline fun CharSequence.reduceIndexed(operation: (index: Int, acc: Char, Char) -> Char): Char {
-    if (isEmpty())
+    if (length == 0)
         throw UnsupportedOperationException("Empty char sequence can't be reduced.")
     var accumulator = this[0]
     for (index in 1..lastIndex) {
@@ -1483,7 +1483,7 @@
  * Creates an [Iterable] instance that wraps the original char sequence returning its characters when being iterated.
  */
 public fun CharSequence.asIterable(): Iterable<Char> {
-    if (this is String && isEmpty()) return emptyList()
+    if (this is String && length == 0) return emptyList()
     return Iterable { this.iterator() }
 }
 
@@ -1491,7 +1491,7 @@
  * Creates a [Sequence] instance that wraps the original char sequence returning its characters when being iterated.
  */
 public fun CharSequence.asSequence(): Sequence<Char> {
-    if (this is String && isEmpty()) return emptySequence()
+    if (this is String && length == 0) return emptySequence()
     return Sequence { this.iterator() }
 }
 
