Repository: GradleUp/shadow (kotlin)

Issue:
Cases like `void method(boolean arg1, org.package.ClassA arg2)` are not covered by `RelocatorRemapper`
> The relocation of method signatures in `@Metadata` annotation fails if there is a primitive argument before a relocating class, such as `void method(boolean a, SomeClass b)` whose descriptor is `(ZLorg/package/SomeClass;)V` which fails the regex [`([\\[()]*)?L([^;]+);?`](https://github.com/GradleUp/shadow/blob/b873c701c1d96c14d5e6f57192c7de18888b9b48/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/internal/RelocatorRemapper.kt#L68).
> 
> Modifying the regex to tolerate primitive descriptors, such as `([\[()BCDFIJSZ]*)?L([^;]+);?` (see 4.3.2 of https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html), should fix this.  
>  

 _Originally posted by @phinner in https://github.com/xpdustry/kotlin-shadow-relocator/issues/30#issuecomment-3275090750_

Pull request description:
https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html

Closes #1730.

---

- [x] [CHANGELOG](https://github.com/GradleUp/shadow/blob/main/docs/changes/README.md)'s "Unreleased" section has been updated, if applicable.

Patch:
diff --git a/docs/changes/README.md b/docs/changes/README.md
index 5fa5eecef..c210100a6 100644
--- a/docs/changes/README.md
+++ b/docs/changes/README.md
@@ -25,6 +25,7 @@
 - Move injecting `Main-Class` manifest attr logic from `doFirst` into `copy`. ([#1724](https://github.com/GradleUp/shadow/pull/1724))
 - Deprecate `InheritManifest`. ([#1722](https://github.com/GradleUp/shadow/pull/1722))
 - Use default `JavaExec` error message when main class is not set. ([#1725](https://github.com/GradleUp/shadow/pull/1725))
+- Update `RelocatorRemapper` class pattern to cover more Java method descriptors. ([#1731](https://github.com/GradleUp/shadow/pull/1731))
 
 ### Fixed
 
diff --git a/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/internal/RelocatorRemapper.kt b/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/internal/RelocatorRemapper.kt
index 922cb4709..27645ce27 100644
--- a/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/internal/RelocatorRemapper.kt
+++ b/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/internal/RelocatorRemapper.kt
@@ -65,6 +65,9 @@ internal class RelocatorRemapper(
   }
 
   private companion object {
-    val classPattern: Pattern = Pattern.compile("([\\[()]*)?L([^;]+);?")
+    /**
+     * https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html
+     */
+    val classPattern: Pattern = Pattern.compile("([\\[()BCDFIJSZ]*)?L([^;]+);?")
   }
 }


Test patch:
diff --git a/src/test/kotlin/com/github/jengelman/gradle/plugins/shadow/relocation/RelocatorRemapperTest.kt b/src/test/kotlin/com/github/jengelman/gradle/plugins/shadow/relocation/RelocatorRemapperTest.kt
index 7bd10f1c6..6a32c7c55 100644
--- a/src/test/kotlin/com/github/jengelman/gradle/plugins/shadow/relocation/RelocatorRemapperTest.kt
+++ b/src/test/kotlin/com/github/jengelman/gradle/plugins/shadow/relocation/RelocatorRemapperTest.kt
@@ -20,6 +20,13 @@ class RelocatorRemapperTest {
   }
 
   private companion object {
+    val primitiveTypes = setOf('B', 'C', 'D', 'F', 'I', 'J', 'S', 'Z')
+
+    val primitiveTypeArguments = primitiveTypes.map {
+      // Methods like `void method(boolean arg1, org.package.ClassA arg2)`
+      Arguments.of("(${it}Lorg/package/ClassA;)V", "(${it}Lshadow/org/package/ClassA;)V")
+    }
+
     @JvmStatic
     fun classSignatureStringConstants() = listOf(
       // Normal class.
@@ -36,6 +43,6 @@ class RelocatorRemapperTest {
       Arguments.of("(Lorg/package/ClassA;Lorg/package/ClassB;)", "(Lshadow/org/package/ClassA;Lshadow/org/package/ClassB;)"),
       // Method return types.
       Arguments.of("()Lorg/package/ClassA;Lorg/package/ClassB;", "()Lshadow/org/package/ClassA;Lshadow/org/package/ClassB;"),
-    )
+    ) + primitiveTypeArguments
   }
 }