@@ -19,11 +19,14 @@ import java.lang.classfile.Signature
1919import java.lang.classfile.Superclass
2020import java.lang.classfile.TypeAnnotation
2121import java.lang.classfile.attribute.AnnotationDefaultAttribute
22+ import java.lang.classfile.attribute.ConstantValueAttribute
2223import java.lang.classfile.attribute.EnclosingMethodAttribute
2324import java.lang.classfile.attribute.ExceptionsAttribute
2425import java.lang.classfile.attribute.InnerClassInfo
2526import java.lang.classfile.attribute.InnerClassesAttribute
2627import java.lang.classfile.attribute.ModuleAttribute
28+ import java.lang.classfile.attribute.ModuleExportInfo
29+ import java.lang.classfile.attribute.ModuleOpenInfo
2730import java.lang.classfile.attribute.ModuleProvideInfo
2831import java.lang.classfile.attribute.NestHostAttribute
2932import java.lang.classfile.attribute.NestMembersAttribute
@@ -37,6 +40,7 @@ import java.lang.classfile.attribute.RuntimeVisibleAnnotationsAttribute
3740import java.lang.classfile.attribute.RuntimeVisibleParameterAnnotationsAttribute
3841import java.lang.classfile.attribute.RuntimeVisibleTypeAnnotationsAttribute
3942import java.lang.classfile.attribute.SignatureAttribute
43+ import java.lang.classfile.constantpool.StringEntry
4044import java.lang.classfile.instruction.ConstantInstruction
4145import java.lang.classfile.instruction.ExceptionCatch
4246import java.lang.classfile.instruction.FieldInstruction
@@ -55,6 +59,7 @@ import java.lang.constant.DynamicCallSiteDesc
5559import java.lang.constant.DynamicConstantDesc
5660import java.lang.constant.MethodHandleDesc
5761import java.lang.constant.MethodTypeDesc
62+ import java.lang.constant.PackageDesc
5863import java.util.regex.Pattern
5964
6065/* *
@@ -75,7 +80,7 @@ internal class RelocatorRemapper(
7580 cle.fieldName().stringValue(),
7681 mapClassDesc(ClassDesc .ofDescriptor(cle.fieldType().stringValue())),
7782 ) { fb ->
78- fb.transform(cle, asFieldTransform())
83+ fb.withFlags(cle.flags().flagsMask()). transform(cle, asFieldTransform())
7984 }
8085 is MethodModel ->
8186 clb.withMethod(
@@ -123,8 +128,28 @@ internal class RelocatorRemapper(
123128 cle.moduleFlagsMask(),
124129 cle.moduleVersion().orElse(null ),
125130 cle.requires(),
126- cle.exports(),
127- cle.opens(),
131+ cle.exports().map { mei ->
132+ ModuleExportInfo .of(
133+ clb
134+ .constantPool()
135+ .packageEntry(
136+ PackageDesc .ofInternalName(map(mei.exportedPackage().asSymbol().internalName()))
137+ ),
138+ mei.exportsFlagsMask(),
139+ mei.exportsTo(),
140+ )
141+ },
142+ cle.opens().map { moi ->
143+ ModuleOpenInfo .of(
144+ clb
145+ .constantPool()
146+ .packageEntry(
147+ PackageDesc .ofInternalName(map(moi.openedPackage().asSymbol().internalName()))
148+ ),
149+ moi.opensFlagsMask(),
150+ moi.opensTo(),
151+ )
152+ },
128153 cle.uses().map { clb.constantPool().classEntry(mapClassDesc(it.asSymbol())!! ) },
129154 cle.provides().map { mp ->
130155 ModuleProvideInfo .of(
@@ -160,6 +185,15 @@ internal class RelocatorRemapper(
160185
161186 private fun asFieldTransform (): FieldTransform = FieldTransform { fb, fe ->
162187 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+ }
163197 is SignatureAttribute -> fb.with (SignatureAttribute .of(mapSignature(fe.asTypeSignature())))
164198 is RuntimeVisibleAnnotationsAttribute ->
165199 fb.with (RuntimeVisibleAnnotationsAttribute .of(mapAnnotations(fe.annotations())))
@@ -436,7 +470,16 @@ internal class RelocatorRemapper(
436470 AnnotationValue .ofAnnotation(mapAnnotation(valObj.annotation()))
437471 is AnnotationValue .OfArray ->
438472 AnnotationValue .ofArray(valObj.values().map(this ::mapAnnotationValue))
439- is AnnotationValue .OfConstant -> valObj
473+ is AnnotationValue .OfConstant -> {
474+ if (valObj is AnnotationValue .OfString ) {
475+ val str = valObj.stringValue()
476+ // mapLiterals=true enables the skipStringConstants check in each relocator.
477+ val mapped = map(str, mapLiterals = true )
478+ if (mapped != str) AnnotationValue .ofString(mapped) else valObj
479+ } else {
480+ valObj
481+ }
482+ }
440483 is AnnotationValue .OfClass -> AnnotationValue .ofClass(mapClassDesc(valObj.classSymbol())!! )
441484 is AnnotationValue .OfEnum ->
442485 AnnotationValue .ofEnum(
@@ -486,7 +529,7 @@ internal class RelocatorRemapper(
486529
487530 for (relocator in relocators) {
488531 if (mapLiterals && relocator.skipStringConstants) {
489- return name
532+ continue
490533 } else if (relocator.canRelocateClass(newName)) {
491534 return prefix + relocator.relocateClass(newName) + suffix
492535 } else if (relocator.canRelocatePath(newName)) {
0 commit comments