Skip to content

Commit 1d1778b

Browse files
CopilotGoooler
andauthored
Fix ConstantValueAttribute remapping and skipStringConstants short-circuit in RelocatorRemapper
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Goooler <10363352+Goooler@users.noreply.github.com>
1 parent 6feb90e commit 1d1778b

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/internal/RelocatorRemapper.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import java.lang.classfile.Signature
1919
import java.lang.classfile.Superclass
2020
import java.lang.classfile.TypeAnnotation
2121
import java.lang.classfile.attribute.AnnotationDefaultAttribute
22+
import java.lang.classfile.attribute.ConstantValueAttribute
2223
import java.lang.classfile.attribute.EnclosingMethodAttribute
2324
import java.lang.classfile.attribute.ExceptionsAttribute
2425
import java.lang.classfile.attribute.InnerClassInfo
@@ -39,6 +40,7 @@ import java.lang.classfile.attribute.RuntimeVisibleAnnotationsAttribute
3940
import java.lang.classfile.attribute.RuntimeVisibleParameterAnnotationsAttribute
4041
import java.lang.classfile.attribute.RuntimeVisibleTypeAnnotationsAttribute
4142
import java.lang.classfile.attribute.SignatureAttribute
43+
import java.lang.classfile.constantpool.StringEntry
4244
import java.lang.classfile.instruction.ConstantInstruction
4345
import java.lang.classfile.instruction.ExceptionCatch
4446
import java.lang.classfile.instruction.FieldInstruction
@@ -183,6 +185,15 @@ internal class RelocatorRemapper(
183185

184186
private fun asFieldTransform(): FieldTransform = FieldTransform { fb, fe ->
185187
when (fe) {
188+
is ConstantValueAttribute -> {
189+
val constant = fe.constant()
190+
if (constant is StringEntry) {
191+
val remapped = map(constant.stringValue(), true)
192+
fb.with(ConstantValueAttribute.of(fb.constantPool().stringEntry(remapped)))
193+
} else {
194+
fb.with(fe)
195+
}
196+
}
186197
is SignatureAttribute -> fb.with(SignatureAttribute.of(mapSignature(fe.asTypeSignature())))
187198
is RuntimeVisibleAnnotationsAttribute ->
188199
fb.with(RuntimeVisibleAnnotationsAttribute.of(mapAnnotations(fe.annotations())))
@@ -518,7 +529,7 @@ internal class RelocatorRemapper(
518529

519530
for (relocator in relocators) {
520531
if (mapLiterals && relocator.skipStringConstants) {
521-
return name
532+
continue
522533
} else if (relocator.canRelocateClass(newName)) {
523534
return prefix + relocator.relocateClass(newName) + suffix
524535
} else if (relocator.canRelocatePath(newName)) {

0 commit comments

Comments
 (0)