From 5103eb15a4b6da8db41b0017397317bb7453df50 Mon Sep 17 00:00:00 2001 From: Graham Date: Sat, 7 Mar 2020 20:37:26 +0000 Subject: [PATCH] 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 --- .../dev/openrs2/asm/classpath/ClassPath.kt | 33 ++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/asm/src/main/java/dev/openrs2/asm/classpath/ClassPath.kt b/asm/src/main/java/dev/openrs2/asm/classpath/ClassPath.kt index 1a7dc447f5..4ade6ecbec 100644 --- a/asm/src/main/java/dev/openrs2/asm/classpath/ClassPath.kt +++ b/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.common.collect.DisjointSet import dev.openrs2.common.collect.ForestDisjointSet +import org.objectweb.asm.Opcodes import org.objectweb.asm.commons.Remapper import org.objectweb.asm.tree.AbstractInsnNode import org.objectweb.asm.tree.ClassNode @@ -120,21 +121,33 @@ class ClassPath( if (superClass != null) { val fields = populateInheritedFieldSets(ancestorCache, disjointSet, superClass) 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 partition2 = disjointSet.add(MemberRef(superClass.name, field)) disjointSet.union(partition1, partition2) + + ancestorsBuilder.add(field) } - ancestorsBuilder.addAll(fields) } for (superInterface in clazz.superInterfaces) { val fields = populateInheritedFieldSets(ancestorCache, disjointSet, superInterface) 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 partition2 = disjointSet.add(MemberRef(superInterface.name, field)) disjointSet.union(partition1, partition2) + + ancestorsBuilder.add(field) } - ancestorsBuilder.addAll(fields) } for (field in clazz.fields) { @@ -175,21 +188,33 @@ class ClassPath( if (superClass != null) { val methods = populateInheritedMethodSets(ancestorCache, disjointSet, superClass) 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 partition2 = disjointSet.add(MemberRef(superClass.name, method)) disjointSet.union(partition1, partition2) + + ancestorsBuilder.add(method) } - ancestorsBuilder.addAll(methods) } for (superInterface in clazz.superInterfaces) { val methods = populateInheritedMethodSets(ancestorCache, disjointSet, superInterface) 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 partition2 = disjointSet.add(MemberRef(superInterface.name, method)) disjointSet.union(partition1, partition2) + + ancestorsBuilder.add(method) } - ancestorsBuilder.addAll(methods) } for (method in clazz.methods) {