Fix static member overrides in populateInherited{Field,Method}Sets

A static member should not override an equivalent member in a superclass
or superinterface. This commit makes us skip the union() calls for
static methods, such that the two disjoint sets are not incorrectly
joined together.

Signed-off-by: Graham <gpe@openrs2.dev>
master
Graham 5 years ago
parent 8cac7a48b5
commit 5103eb15a4
  1. 33
      asm/src/main/java/dev/openrs2/asm/classpath/ClassPath.kt

@ -5,6 +5,7 @@ import dev.openrs2.asm.MemberRef
import dev.openrs2.asm.toBinaryClassName import dev.openrs2.asm.toBinaryClassName
import dev.openrs2.common.collect.DisjointSet import dev.openrs2.common.collect.DisjointSet
import dev.openrs2.common.collect.ForestDisjointSet import dev.openrs2.common.collect.ForestDisjointSet
import org.objectweb.asm.Opcodes
import org.objectweb.asm.commons.Remapper import org.objectweb.asm.commons.Remapper
import org.objectweb.asm.tree.AbstractInsnNode import org.objectweb.asm.tree.AbstractInsnNode
import org.objectweb.asm.tree.ClassNode import org.objectweb.asm.tree.ClassNode
@ -120,21 +121,33 @@ class ClassPath(
if (superClass != null) { if (superClass != null) {
val fields = populateInheritedFieldSets(ancestorCache, disjointSet, superClass) val fields = populateInheritedFieldSets(ancestorCache, disjointSet, superClass)
for (field in fields) { for (field in fields) {
val access = clazz.getFieldAccess(field)
if (access != null && access and Opcodes.ACC_STATIC != 0) {
continue
}
val partition1 = disjointSet.add(MemberRef(clazz.name, field)) val partition1 = disjointSet.add(MemberRef(clazz.name, field))
val partition2 = disjointSet.add(MemberRef(superClass.name, field)) val partition2 = disjointSet.add(MemberRef(superClass.name, field))
disjointSet.union(partition1, partition2) disjointSet.union(partition1, partition2)
ancestorsBuilder.add(field)
} }
ancestorsBuilder.addAll(fields)
} }
for (superInterface in clazz.superInterfaces) { for (superInterface in clazz.superInterfaces) {
val fields = populateInheritedFieldSets(ancestorCache, disjointSet, superInterface) val fields = populateInheritedFieldSets(ancestorCache, disjointSet, superInterface)
for (field in fields) { for (field in fields) {
val access = clazz.getFieldAccess(field)
if (access != null && access and Opcodes.ACC_STATIC != 0) {
continue
}
val partition1 = disjointSet.add(MemberRef(clazz.name, field)) val partition1 = disjointSet.add(MemberRef(clazz.name, field))
val partition2 = disjointSet.add(MemberRef(superInterface.name, field)) val partition2 = disjointSet.add(MemberRef(superInterface.name, field))
disjointSet.union(partition1, partition2) disjointSet.union(partition1, partition2)
ancestorsBuilder.add(field)
} }
ancestorsBuilder.addAll(fields)
} }
for (field in clazz.fields) { for (field in clazz.fields) {
@ -175,21 +188,33 @@ class ClassPath(
if (superClass != null) { if (superClass != null) {
val methods = populateInheritedMethodSets(ancestorCache, disjointSet, superClass) val methods = populateInheritedMethodSets(ancestorCache, disjointSet, superClass)
for (method in methods) { for (method in methods) {
val access = clazz.getMethodAccess(method)
if (access != null && access and Opcodes.ACC_STATIC != 0) {
continue
}
val partition1 = disjointSet.add(MemberRef(clazz.name, method)) val partition1 = disjointSet.add(MemberRef(clazz.name, method))
val partition2 = disjointSet.add(MemberRef(superClass.name, method)) val partition2 = disjointSet.add(MemberRef(superClass.name, method))
disjointSet.union(partition1, partition2) disjointSet.union(partition1, partition2)
ancestorsBuilder.add(method)
} }
ancestorsBuilder.addAll(methods)
} }
for (superInterface in clazz.superInterfaces) { for (superInterface in clazz.superInterfaces) {
val methods = populateInheritedMethodSets(ancestorCache, disjointSet, superInterface) val methods = populateInheritedMethodSets(ancestorCache, disjointSet, superInterface)
for (method in methods) { for (method in methods) {
val access = clazz.getMethodAccess(method)
if (access != null && access and Opcodes.ACC_STATIC != 0) {
continue
}
val partition1 = disjointSet.add(MemberRef(clazz.name, method)) val partition1 = disjointSet.add(MemberRef(clazz.name, method))
val partition2 = disjointSet.add(MemberRef(superInterface.name, method)) val partition2 = disjointSet.add(MemberRef(superInterface.name, method))
disjointSet.union(partition1, partition2) disjointSet.union(partition1, partition2)
ancestorsBuilder.add(method)
} }
ancestorsBuilder.addAll(methods)
} }
for (method in clazz.methods) { for (method in clazz.methods) {

Loading…
Cancel
Save