Skip to content

Commit 35b08ba

Browse files
jpobstjonpryor
authored andcommitted
[ApiXmlAdjuster] Guard against NRE when writing generic constraints. (#495)
Context: #466 Context: #467 When attempting to bind [`kotlin-stdlib-1.3.41.jar`][0], `generator` crashes with the following exception: System.NullReferenceException: Object reference not set to an instance of an object at Xamarin.Android.Tools.ApiXmlAdjuster.JavaApiXmlGeneratorExtensions.Save (Xamarin.Android.Tools.ApiXmlAdjuster.JavaTypeParameters typeParameters, System.Xml.XmlWriter writer, System.String indent) at Xamarin.Android.Tools.ApiXmlAdjuster.JavaApiXmlGeneratorExtensions.SaveCommon (Xamarin.Android.Tools.ApiXmlAdjuster.JavaMember m, System.Xml.XmlWriter writer, System.String elementName, System.String abs, System.String native, System.String ret, System.String sync, System.String transient, System.String type, System.String typeGeneric, System.String value, System.String volat, Xamarin.Android.Tools.ApiXmlAdjuster.JavaTypeParameters typeParameters, System.Collections.Generic.IEnumerable`1[T] parameters, System.Collections.Generic.IEnumerable`1[T] exceptions, System.Nullable`1[T] extBridge, System.String jniReturn, System.Nullable`1[T] extSynthetic) at Xamarin.An/droid.Tools.ApiXmlAdjuster.JavaApiXmlGeneratorExtensions.Save (Xamarin.Android.Tools.ApiXmlAdjuster.JavaMethod method, System.Xml.XmlWriter writer) at Xamarin.Android.Tools.ApiXmlAdjuster.JavaApiXmlGeneratorExtensions.SaveTypeCommon (Xamarin.Android.Tools.ApiXmlAdjuster.JavaType cls, System.Xml.XmlWriter writer, System.String elementName, System.String abs, System.String ext, System.String extgen, System.String jniExt) at Xamarin.Android.Tools.ApiXmlAdjuster.JavaApiXmlGeneratorExtensions.Save (Xamarin.Android.Tools.ApiXmlAdjuster.JavaClass cls, System.Xml.XmlWriter writer) at Xamarin.Android.Tools.ApiXmlAdjuster.JavaApiXmlGeneratorExtensions.Save (Xamarin.Android.Tools.ApiXmlAdjuster.JavaApi api, System.Xml.XmlWriter writer) at Xamarin.Android.Tools.ApiXmlAdjuster.JavaApiXmlGeneratorExtensions.Save (Xamarin.Android.Tools.ApiXmlAdjuster.JavaApi api, System.String xmlfile) at Xamarin.Android.Tools.ApiXmlAdjuster.Adjuster.Process (System.String inputXmlFile, MonoDroid.Generation.CodeGenerationOptions opt, MonoDroid.Generation.GenBase[] gens, System.String outputXmlFile, System.Int32 reportVerbosity) at Xamarin.Android.Binder.CodeGenerator.Run (Xamarin.Android.Binder.CodeGeneratorOptions options, Java.Interop.Tools.Cecil.DirectoryAssemblyResolver resolver) at Xamarin.Android.Binder.CodeGenerator.Run (Xamarin.Android.Binder.CodeGeneratorOptions options) at Xamarin.Android.Binder.CodeGenerator.Main (System.String[] args) We are still investigating *why* this happens and how it should be appropriately fixed. In the meantime, to "unblock" developers attempting to bind binding Kotlin libraries in Visual Studio 16.4 Preview 2, simply prevent the `NullReferenceException` from being generated generated. This at least lets people get past the crash so they can apply fixups in `Metadata.xml` to continue. (This `NullReferenceException` happens before the `metadata` stage; there's nothing a user can currently do.) I will be making our Kotlin bindings more "correct" in future sprints. [0]: https://search.maven.org/remotecontent?filepath=org/jetbrains/kotlin/kotlin-stdlib/1.3.41/kotlin-stdlib-1.3.41.jar
1 parent b98f423 commit 35b08ba

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/Xamarin.Android.Tools.ApiXmlAdjuster/JavaApiXmlGeneratorExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ static void Save (this JavaTypeParameters typeParameters, XmlWriter writer, stri
124124
// jar2xml does not emit that either.
125125
var gcs = tp.GenericConstraints.GenericConstraints;
126126
var gctr = gcs.Count == 1 ? gcs [0].ResolvedType : null;
127-
if (gctr == null || gctr.ReferencedType.FullName != "java.lang.Object")
127+
if (gctr?.ReferencedType?.FullName != "java.lang.Object")
128128
{
129129
writer.WriteStartElement ("genericConstraints");
130130
foreach (var g in tp.GenericConstraints.GenericConstraints) {

0 commit comments

Comments
 (0)