Skip to content
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

[Mono.Android] Data sharing and Close() overrides #9103

Merged
merged 1 commit into from
Jul 12, 2024
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
10 changes: 4 additions & 6 deletions src/Mono.Android/Android.Runtime/InputStreamInvoker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ protected override void Dispose (bool disposing)
if (disposing && BaseInputStream != null) {
try {
BaseFileChannel = null;
BaseInputStream.Close ();
if (BaseInputStream.PeerReference.IsValid) {
BaseInputStream.Close ();
}
BaseInputStream.Dispose ();
} catch (Java.IO.IOException ex) when (JNIEnv.ShouldWrapJavaException (ex)) {
throw new IOException (ex.Message, ex);
Expand All @@ -58,11 +60,7 @@ protected override void Dispose (bool disposing)
//
public override void Close ()
{
try {
BaseInputStream.Close ();
} catch (Java.IO.IOException ex) when (JNIEnv.ShouldWrapJavaException (ex)) {
throw new IOException (ex.Message, ex);
}
base.Close ();
jonpryor marked this conversation as resolved.
Show resolved Hide resolved
}

public override void Flush ()
Expand Down
10 changes: 4 additions & 6 deletions src/Mono.Android/Android.Runtime/OutputStreamInvoker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@ public OutputStreamInvoker (Java.IO.OutputStream stream)
//
public override void Close ()
{
try {
BaseOutputStream.Close ();
} catch (Java.IO.IOException ex) when (JNIEnv.ShouldWrapJavaException (ex)) {
throw new IOException (ex.Message, ex);
}
base.Close ();
}

//
Expand All @@ -50,7 +46,9 @@ protected override void Dispose (bool disposing)
{
if (disposing && BaseOutputStream != null) {
try {
BaseOutputStream.Close ();
if (BaseOutputStream.PeerReference.IsValid) {
BaseOutputStream.Close ();
}
BaseOutputStream.Dispose ();
} catch (Java.IO.IOException ex) when (JNIEnv.ShouldWrapJavaException (ex)) {
throw new IOException (ex.Message, ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ namespace Android.RuntimeTests
[TestFixture]
public class InputStreamInvokerTest
{
[Test]
public void Disposing_Shared_Data_Does_Not_Throw_IOE ()
{
var javaInputStream = new Java.IO.ByteArrayInputStream (new byte[]{0x1, 0x2, 0x3, 0x4});
var invoker = new InputStreamInvoker (javaInputStream);
javaInputStream.Dispose ();
invoker.Dispose ();
}

[Test]
public void InputStreamTest ()
{
Expand Down
Loading