Skip to content

[ApiXmlAdjuster] Guard against NRE when writing generic constraints. #495

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 30, 2019

Conversation

jpobst
Copy link
Contributor

@jpobst jpobst commented Sep 30, 2019

Context: #466

In an effort to get people unblocked on binding Kotlin libraries in 16.4 Preview 2, this PR simply guards against the NRE generated. It does not attempt to figure out the underlying problem and generate better code.

This at least lets people get past the crash so they can do fixups in metadata.xml to continue. I will be making our Kotlin bindings more "correct" in future sprints. (This NRE happens before the metadata stage so there's nothing a user can currently do.)

@jonpryor jonpryor merged commit 2716edf into master Sep 30, 2019
@jonpryor jonpryor deleted the adjuster-nre branch September 30, 2019 19:01
jonpryor pushed a commit that referenced this pull request Sep 30, 2019
…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
@jpobst jpobst modified the milestone: d16-4 Oct 31, 2019
@github-actions github-actions bot locked and limited conversation to collaborators Apr 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants