Fix incorrect marking of fields as final if no constructor existed

Signed-off-by: Graham <gpe@openrs2.dev>
bzip2
Graham 5 years ago
parent d410f87240
commit 6c26fb8b9c
  1. 18
      deob/src/main/java/dev/openrs2/deob/transform/FinalFieldTransformer.kt

@ -98,6 +98,24 @@ class FinalFieldTransformer : Transformer() {
return false return false
} }
override fun transformClass(classPath: ClassPath, library: Library, clazz: ClassNode): Boolean {
// if a class has no constructor all its fields must be non-final
val hasInstanceConstructor = clazz.methods.any { it.name == "<init>" }
val hasStaticConstructor = clazz.methods.any { it.name == "<clinit>" }
for (field in clazz.fields) {
val fieldStatic = (field.access and Opcodes.ACC_STATIC) != 0
if ((!hasInstanceConstructor && !fieldStatic) || (!hasStaticConstructor && fieldStatic)) {
val partition = inheritedFieldSets[MemberRef(clazz, field)]!!
nonFinalFields += partition
}
}
return false
}
override fun transformField(classPath: ClassPath, library: Library, clazz: ClassNode, field: FieldNode): Boolean { override fun transformField(classPath: ClassPath, library: Library, clazz: ClassNode, field: FieldNode): Boolean {
if ((field.access and Opcodes.ACC_VOLATILE) != 0) { if ((field.access and Opcodes.ACC_VOLATILE) != 0) {
val partition = inheritedFieldSets[MemberRef(clazz, field)]!! val partition = inheritedFieldSets[MemberRef(clazz, field)]!!

Loading…
Cancel
Save