Skip to content

Commit 1f0c03d

Browse files
committed
Generate Threshold{Class,Type} properties for all classes
If a class derives from `Java.Lang.Object` it should have the two properties mentioned above generated, so that it is possible to find methods in the correct instance of Java class instance that is wrapped by our managed class. Generator used to decide whether or not to generate these properties based on the presence of class members (fields, constructors, methods and properties) or whether the class is an annotation in the API description file. However there exist a number of classes (for instance `Inet4Address`) which don't have any of the members present and yet they should have the Threshold* properties generated for the reasons described above. The `HasClassHandle` property which was used to determine whether the class should get these properties (among a handful of other members) doesn't serve its purpose correctly leading to corner cases when the `Threshold*` properties are missing and causing runtime bugs (e.g. calling `GetAddress()` on an instance of `Inet4Address` returns `null` even though the underlying Java class has the information - the call never reaches `Inet4Address` instance and thus returns nothing). Replacing `HasClassHandle` with a simple check for whether the class in question derives from `Java.Lang.Object` is the correct fix that ensures the missing properties are generated. Fixe https://bugzilla.xamarin.com/show_bug.cgi?id=56537
1 parent 57e9501 commit 1f0c03d

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

tools/generator/ClassGen.cs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,6 @@ public override string NativeType {
160160
get { return "IntPtr"; }
161161
}
162162

163-
public bool HasClassHandle {
164-
get { return ctors.Count > 0 || Fields.Count > 0 || Methods.Count > 0 || Properties.Count > 0 || IsAnnotation; }
165-
}
166-
167163
public IList<Ctor> Ctors {
168164
get { return ctors; }
169165
}
@@ -449,17 +445,16 @@ public override void Generate (StreamWriter sw, string indent, CodeGenerationOpt
449445
sw.WriteLine ();
450446
}
451447

452-
if (HasClassHandle) {
453-
bool requireNew = false;
448+
bool requireNew = InheritsObject;
449+
if (!requireNew) {
454450
for (var bg = BaseGen; bg != null && bg is XmlClassGen; bg = bg.BaseGen) {
455-
if (bg.HasClassHandle) {
451+
if (bg.InheritsObject) {
456452
requireNew = true;
457453
break;
458454
}
459455
}
460-
461-
opt.CodeGenerator.WriteClassHandle (this, sw, indent, opt, requireNew);
462456
}
457+
opt.CodeGenerator.WriteClassHandle (this, sw, indent, opt, requireNew);
463458

464459
GenConstructors (sw, indent + "\t", opt);
465460

0 commit comments

Comments
 (0)