-
-
Notifications
You must be signed in to change notification settings - Fork 423
Relocation does not work properly for some string constants #1403
Description
Expected and Results
When attempting to shade and relocate a class that has string constants of descriptors & signatures for fields & methods, the constants are only partially relocated.
For the examples below, assume a shadowJar task of shadowJar { relocate 'org.package', 'shadow.org.package' }
Here are some examples of string constants that are or are not relocated properly
Lorg/package/ClassA;is properly relocated toLshadow/org/package/ClassA;Lorg/package/ClassA;Lorg/package/ClassB;fails to relocateClassBresulting inLshadow/org/package/ClassA;Lorg/package/ClassB;Ljava/lang/Object;Lorg/package/ClassB;fails to relocateClassB(Lorg/package/ClassA;Lorg/package/ClassB;)fails to relocate bothClassAandClassB()Lorg/package/ClassA;Lorg/package/ClassB;fails to relocate bothClassAandClassB
I could list a lot of similar examples, but you probably get the point by now.
Related environent and versions
Environment
- Shadow Gradle Plugin
9.0.0-beta12 - Gradle
8.14-rc-1 - JDK
GraalVM CE 24 - IDE
IntelliJ Community 2025.1 - OS
Windows 11
Reproduction steps
- Add
org.mozilla:rhino:1.7.15as a shaded dependency in gradle - Configure the shadowJar task for relocation
relocate 'org.mozilla', 'shadow.org.mozilla' - Build the jar
- Open
shadow.org.mozilla.javascript.optimizer.BodyCodegen.classfrom the built jar and notice the many string constants that failed to relocate properly
Anything else?
I tried using an include when relocating in hopes that using regex would be able to catch these cases, but from my understanding the relocate task only matches the start of a string.
I also found that using relocate '()Lorg/mozilla', 'Lshadow/org.mozilla' does catch stuff like ()Lorg/mozilla/javascript/Context;, but it still only works for the first class in the case of multiple org.mozilla classes being present in the signature.
Similarly, I found that trying to use relocate '(Lorg/mozilla', 'Lshadow/org.mozilla' fails to build due to a regex parser failing, but I find it strange that the () in ()Lorg/mozilla is treated as a string literal instead of a capturing group. From what I tested, regex does not seem to work with relocation other than include, exclude, and maybe any other closure parameters.