Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ public override void Resolve (JavaTypeCollection types, ICollection<JavaUnresolv
throw;
}

// Apparently some Java obfuscator sets a class's base type to itself, which
// results in a stack overflow. Check for this case and remove the offending type.
if (BaseTypeReference.ReferencedType is JavaClassModel jcm && jcm == this) {
unresolvables.Add (new JavaUnresolvableModel (this, BaseTypeGeneric, UnresolvableType.InvalidBaseType));
throw new JavaTypeResolutionException (BaseTypeGeneric);
}

// We don't resolve reference-only types by default, so if our base class
// is a reference only type, we need to force it to resolve here. This will be
// needed later when we attempt to resolve base methods.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public string GetDisplayMessage ()
$"The type '{member?.DeclaringType.FullName}' was removed because the required {GetUnresolvableType ()} '{GetUnresolvable ()}' was removed because its name contains a dollar sign." :
$"The {GetUnresolvableType ()} '{GetUnresolvable ()}' was removed because its name contains a dollar sign.";

if (Type == UnresolvableType.InvalidBaseType)
return $"The {GetUnresolvableType ()} '{GetUnresolvable ()}' was removed because the base type '{MissingType}' is invalid.";

if (Unresolvable is JavaTypeModel)
return $"The {GetUnresolvableType ()} '{GetUnresolvable ()}' was removed because the Java {GetReason ()} '{MissingType}' could not be found.";

Expand Down Expand Up @@ -77,6 +80,7 @@ public enum UnresolvableType
ReturnType,
ParameterType,
BaseType,
ImplementsType
ImplementsType,
InvalidBaseType,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,30 @@ public void InheritedGenericTypeParameters ()
Assert.IsNotNull (t.Methods.SingleOrDefault (m => m.Name == "DoT"), "Method with generic T not found");
Assert.IsNotNull (t.Methods.SingleOrDefault (m => m.Name == "DoU"), "Method with generic U not found");
}

[Test]
public void InvalidBaseTypeResolution ()
{
var api = new JavaTypeCollection ();

// Create "my.ns" package
var my_ns = api.AddPackage ("my.ns", "my/ns");

// Create new "my.ns.MyObject" type with "my.ns.MyObject" as base type
var jlo = JavaApiTestHelper.CreateClass (my_ns, "MyObject", javaBaseType: "my.ns.MyObject", javaBaseTypeGeneric: "my.ns.MyObject");

api.AddType (jlo);

// Run the resolver
var results = api.ResolveCollection ();

// Ensure we marked it as unresolvable
Assert.AreEqual (1, results.Count);
Assert.AreEqual (1, results [0].Unresolvables.Count);
Assert.AreEqual ("The class '[Class] my.ns.MyObject' was removed because the base type 'my.ns.MyObject' is invalid.", results [0].Unresolvables [0].GetDisplayMessage ());

// Ensure we removed the type from the collection
Assert.AreEqual (0, api.TypesFlattened.Count);
}
}
}