Open brendanzagaeski opened 4 years ago
Additional background context: From a first quick chat with @jonpryor, it sounded like this might be unintentional, so I added an issue here to help with tracking potential changes to the behavior.
Another related case is that with the new exception mode enabled Android.Runtime.InputStreamInvoker.Read()
will at the moment throw things like:
Java.Lang.IndexOutOfBoundsException
instead of ArgumentException
or ArgumentOutOfRangeException
Java.Lang.NullPointerException
instead of ArgumentNullException
System.IO.IOException
instead of ObjectDisposedException
One more interesting case is AndroidClientHandler
, which currently throws exceptions like Java.Net.UnknownHostException
instead of System.Net.Http.HttpRequestException
. I think that type might have been unintentionally overlooked in the first set of changes because it isn't a binding for an existing Android or Java type.
Adjusting AndroidClientHandler.SendAsync()
to throw the documented excpetions for HttpClient.SendAsync()
and HttpClientHandler.SendAsync()
will fix https://github.com/xamarin/xamarin-android/issues/3216.
Context
https://github.com/xamarin/xamarin-android/commit/60363ef45cd6994a322adac1b73d4271b0658c1e added an option to wrap
Java
exception types in .NET exception types for certain Android APIs.JavaDictionary.Get()
is an example:https://github.com/xamarin/xamarin-android/blob/8d7557aad23a3c0724e1996aade3072b1a09f298/src/Mono.Android/Android.Runtime/JavaDictionary.cs#L72-L86
Expected behavior
JavaDictionary
inherits fromJava.Lang.Object
and implementsIDictionary
:https://github.com/xamarin/xamarin-android/blob/8d7557aad23a3c0724e1996aade3072b1a09f298/src/Mono.Android/Android.Runtime/JavaDictionary.cs#L12
The documentation for the
IDictionary.Item[Object]
indexer property mentions two exceptions:ArgumentNullException
NotSupportedException
Actual behavior
JavaDictionary.Get()
can currently throw the following two different exceptions instead:InvalidCastException
NullReferenceException
Depending on the goals of the Java exception wrapping, throwing different System exceptions from
JavaDictionary.Get()
than the ones documented forIDictionary.Item[Object]
might be unintended. Maybe only the exception conditions documented forIDictionary.Item[Object]
(like "key
isnull
") need to be surfaced as System exceptions, and other exceptions, if any, can be left as Java exceptions?Related scenarios
If this
JavaDictionary.Get()
scenario does look good to change, then there are probably a few additional similar cases to change too.Another slightly different case is
JavaCollection.Add()
. I think it might have been wrapped becauseJavaCollection
implementsICollection
, but I just noticed today that the non-genericICollection
interface doesn't include anAdd()
method. Only the genericICollection<T>
includes anAdd()
method. So maybeJavaCollection.Add()
doesn't need to wrap any exceptions?