Fixed: #2498 Public traits with same name were not distinguishable

This commit is contained in:
Jindra Petřík
2025-08-01 18:24:56 +02:00
parent 95e8c6d086
commit a76ce37d33
6 changed files with 10 additions and 7 deletions

View File

@@ -212,7 +212,7 @@ public class FullMultinameAVM2Item extends AVM2Item {
writer.append("*");
} else {
Reference<DottedChain> customNsRef = new Reference<>(null);
String localName = constants.getMultiname(multinameIndex).getNameAndCustomNamespace(localData.usedDeobfuscations, localData.abc, localData.fullyQualifiedNames, false, true, customNsRef);
String localName = constants.getMultiname(multinameIndex).getNameAndCustomNamespace(localData.usedDeobfuscations, localData.abc, fullyQualifiedNames, false, true, customNsRef);
DottedChain customNs = customNsRef.getVal();
if (customNs != null) {
String nsname = customNs.getLast();

View File

@@ -89,7 +89,7 @@ public class ClassNameMultinameUsage extends MultinameUsage implements Definitio
}
}
if (other instanceof ClassNameMultinameUsage) {
return sameMultinameName(other);
return sameMultinameName(other, true);
}
return false;
}

View File

@@ -51,7 +51,7 @@ public class ConstVarNameMultinameUsage extends ConstVarMultinameUsage implement
if ((other instanceof ConstVarNameMultinameUsage) || (other instanceof MethodNameMultinameUsage)) {
TraitMultinameUsage otherTrait = (TraitMultinameUsage) other;
if (otherTrait.classIndex == classIndex && otherTrait.traitsType == traitsType && otherTrait.parentTraitIndex == parentTraitIndex) {
if (other.sameMultinameName(this)) {
if (other.sameMultinameName(this, false)) {
return true;
}
}

View File

@@ -52,7 +52,7 @@ public class MethodNameMultinameUsage extends MethodMultinameUsage implements De
if ((other instanceof MethodNameMultinameUsage) || (other instanceof ConstVarNameMultinameUsage)) {
TraitMultinameUsage otherTrait = (TraitMultinameUsage) other;
if (otherTrait.classIndex == classIndex && otherTrait.traitsType == traitsType && otherTrait.parentTraitIndex == parentTraitIndex) {
if (other.sameMultinameName(this)) {
if (other.sameMultinameName(this, false)) {
if (other instanceof MethodNameMultinameUsage) {
MethodNameMultinameUsage otherM = (MethodNameMultinameUsage) other;

View File

@@ -75,9 +75,10 @@ public abstract class MultinameUsage implements Usage {
/**
* Checks if this multiname name is the same as other multiname name.
* @param other Other multiname usage
* @param includePublic Include public namespaces?
* @return True if names are the same
*/
protected boolean sameMultinameName(MultinameUsage other) {
protected boolean sameMultinameName(MultinameUsage other, boolean includePublic) {
Multiname thisM = abc.constants.getMultiname(multinameIndex);
Multiname otherM = other.abc.constants.getMultiname(other.multinameIndex);
if (thisM == null && otherM == null) {
@@ -106,8 +107,8 @@ public abstract class MultinameUsage implements Usage {
}
//public or package internal are colliding when have same package ns
if ((thisNs.kind == Namespace.KIND_PACKAGE || thisNs.kind == Namespace.KIND_PACKAGE_INTERNAL)
&& (otherNs.kind == Namespace.KIND_PACKAGE || otherNs.kind == Namespace.KIND_PACKAGE_INTERNAL)) {
if (includePublic && ((thisNs.kind == Namespace.KIND_PACKAGE || thisNs.kind == Namespace.KIND_PACKAGE_INTERNAL)
&& (otherNs.kind == Namespace.KIND_PACKAGE || otherNs.kind == Namespace.KIND_PACKAGE_INTERNAL))) {
return Objects.equals(thisNs.getName(abc.constants), otherNs.getName(other.abc.constants));
}