Skip to content

Commit

Permalink
Fix nullable annotation for BeginXx AsyncCallback (dotnet#31934)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephentoub authored Feb 8, 2020
1 parent 9013928 commit 0790041
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public override void Write(ReadOnlySpan<byte> buffer)
_stream.Write(buffer);
}

public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object? state)
public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state)
{
_position += count;
return _stream.BeginWrite(buffer, offset, count, callback, state);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ public partial class IsolatedStorageFileStream : System.IO.FileStream
public override long Length { get { throw null; } }
public override long Position { get { throw null; } set { } }
public override Microsoft.Win32.SafeHandles.SafeFileHandle SafeFileHandle { get { throw null; } }
public override System.IAsyncResult BeginRead(byte[] buffer, int offset, int numBytes, System.AsyncCallback userCallback, object? stateObject) { throw null; }
public override System.IAsyncResult BeginWrite(byte[] buffer, int offset, int numBytes, System.AsyncCallback userCallback, object? stateObject) { throw null; }
public override System.IAsyncResult BeginRead(byte[] buffer, int offset, int numBytes, System.AsyncCallback? userCallback, object? stateObject) { throw null; }
public override System.IAsyncResult BeginWrite(byte[] buffer, int offset, int numBytes, System.AsyncCallback? userCallback, object? stateObject) { throw null; }
protected override void Dispose(bool disposing) { }
public override System.Threading.Tasks.ValueTask DisposeAsync() { throw null; }
public override int EndRead(System.IAsyncResult asyncResult) { throw null; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,12 +302,12 @@ public override void WriteByte(byte value)
_fs.WriteByte(value);
}

public override IAsyncResult BeginRead(byte[] array, int offset, int numBytes, AsyncCallback userCallback, object? stateObject)
public override IAsyncResult BeginRead(byte[] array, int offset, int numBytes, AsyncCallback? userCallback, object? stateObject)
{
return _fs.BeginRead(array, offset, numBytes, userCallback, stateObject);
}

public override IAsyncResult BeginWrite(byte[] array, int offset, int numBytes, AsyncCallback userCallback, object? stateObject)
public override IAsyncResult BeginWrite(byte[] array, int offset, int numBytes, AsyncCallback? userCallback, object? stateObject)
{
return _fs.BeginWrite(array, offset, numBytes, userCallback, stateObject);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ private void PrepareForWriting()
Dispose(false);
}

public override IAsyncResult BeginRead(byte[] array, int offset, int numBytes, AsyncCallback callback, object? state)
public override IAsyncResult BeginRead(byte[] array, int offset, int numBytes, AsyncCallback? callback, object? state)
{
if (array == null)
throw new ArgumentNullException(nameof(array));
Expand All @@ -870,7 +870,7 @@ public override IAsyncResult BeginRead(byte[] array, int offset, int numBytes, A
return TaskToApm.Begin(ReadAsyncTask(array, offset, numBytes, CancellationToken.None), callback, state);
}

public override IAsyncResult BeginWrite(byte[] array, int offset, int numBytes, AsyncCallback callback, object? state)
public override IAsyncResult BeginWrite(byte[] array, int offset, int numBytes, AsyncCallback? callback, object? state)
{
if (array == null)
throw new ArgumentNullException(nameof(array));
Expand Down
16 changes: 8 additions & 8 deletions src/libraries/System.Private.CoreLib/src/System/IO/Stream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ protected virtual WaitHandle CreateWaitHandle()
return new ManualResetEvent(false);
}

public virtual IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object? state)
public virtual IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state)
{
return BeginReadInternal(buffer, offset, count, callback, state, serializeAsynchronously: false, apm: true);
}
Expand Down Expand Up @@ -503,7 +503,7 @@ private Task<int> BeginEndReadAsync(byte[] buffer, int offset, int count)



public virtual IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object? state)
public virtual IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state)
{
return BeginWriteInternal(buffer, offset, count, callback, state, serializeAsynchronously: false, apm: true);
}
Expand Down Expand Up @@ -884,7 +884,7 @@ protected virtual void ObjectInvariant()
{
}

internal IAsyncResult BlockingBeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object? state)
internal IAsyncResult BlockingBeginRead(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state)
{
// To avoid a race with a stream's position pointer & generating conditions
// with internal buffer indexes in our own streams that
Expand Down Expand Up @@ -913,7 +913,7 @@ internal static int BlockingEndRead(IAsyncResult asyncResult)
return SynchronousAsyncResult.EndRead(asyncResult);
}

internal IAsyncResult BlockingBeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object? state)
internal IAsyncResult BlockingBeginWrite(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state)
{
// To avoid a race condition with a stream's position pointer & generating conditions
// with internal buffer indexes in our own streams that
Expand Down Expand Up @@ -1012,7 +1012,7 @@ public override Task FlushAsync(CancellationToken cancellationToken)
Task.CompletedTask;
}

public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object? state)
public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state)
{
if (!CanRead) throw Error.GetReadNotSupported();

Expand All @@ -1027,7 +1027,7 @@ public override int EndRead(IAsyncResult asyncResult)
return BlockingEndRead(asyncResult);
}

public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object? state)
public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state)
{
if (!CanWrite) throw Error.GetWriteNotSupported();

Expand Down Expand Up @@ -1304,7 +1304,7 @@ public override int ReadByte()
return _stream.ReadByte();
}

public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object? state)
public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state)
{
#if CORERT
throw new NotImplementedException(); // TODO: https://github.com/dotnet/corert/issues/3251
Expand Down Expand Up @@ -1365,7 +1365,7 @@ public override void WriteByte(byte b)
_stream.WriteByte(b);
}

public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object? state)
public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state)
{
#if CORERT
throw new NotImplementedException(); // TODO: https://github.com/dotnet/corert/issues/3251
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1332,8 +1332,8 @@ public BufferedStream(System.IO.Stream stream, int bufferSize) { }
public override long Length { get { throw null; } }
public override long Position { get { throw null; } set { } }
public System.IO.Stream UnderlyingStream { get { throw null; } }
public override System.IAsyncResult BeginRead(byte[] buffer, int offset, int count, System.AsyncCallback callback, object? state) { throw null; }
public override System.IAsyncResult BeginWrite(byte[] buffer, int offset, int count, System.AsyncCallback callback, object? state) { throw null; }
public override System.IAsyncResult BeginRead(byte[] buffer, int offset, int count, System.AsyncCallback? callback, object? state) { throw null; }
public override System.IAsyncResult BeginWrite(byte[] buffer, int offset, int count, System.AsyncCallback? callback, object? state) { throw null; }
public override void CopyTo(System.IO.Stream destination, int bufferSize) { }
public override System.Threading.Tasks.Task CopyToAsync(System.IO.Stream destination, int bufferSize, System.Threading.CancellationToken cancellationToken) { throw null; }
protected override void Dispose(bool disposing) { }
Expand Down Expand Up @@ -1383,8 +1383,8 @@ public MemoryStream(int capacity) { }
public virtual int Capacity { get { throw null; } set { } }
public override long Length { get { throw null; } }
public override long Position { get { throw null; } set { } }
public override System.IAsyncResult BeginRead(byte[] buffer, int offset, int count, System.AsyncCallback callback, object? state) { throw null; }
public override System.IAsyncResult BeginWrite(byte[] buffer, int offset, int count, System.AsyncCallback callback, object? state) { throw null; }
public override System.IAsyncResult BeginRead(byte[] buffer, int offset, int count, System.AsyncCallback? callback, object? state) { throw null; }
public override System.IAsyncResult BeginWrite(byte[] buffer, int offset, int count, System.AsyncCallback? callback, object? state) { throw null; }
public override void CopyTo(System.IO.Stream destination, int bufferSize) { }
public override void CopyTo(System.Buffers.ReadOnlySpanAction<byte, object?> callback, object? state, int bufferSize) { }
public override System.Threading.Tasks.Task CopyToAsync(System.IO.Stream destination, int bufferSize, System.Threading.CancellationToken cancellationToken) { throw null; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ private async ValueTask<int> ReadFromUnderlyingStreamAsync(
}
}

public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object? state) =>
public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state) =>
TaskToApm.Begin(ReadAsync(buffer, offset, count, CancellationToken.None), callback, state);

public override int EndRead(IAsyncResult asyncResult) =>
Expand Down Expand Up @@ -1210,7 +1210,7 @@ private async ValueTask WriteToUnderlyingStreamAsync(
}
}

public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object? state) =>
public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state) =>
TaskToApm.Begin(WriteAsync(buffer, offset, count, CancellationToken.None), callback, state);

public override void EndWrite(IAsyncResult asyncResult) =>
Expand Down
8 changes: 4 additions & 4 deletions src/libraries/System.Runtime/ref/System.Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5411,8 +5411,8 @@ public FileStream(string path, System.IO.FileMode mode, System.IO.FileAccess acc
public virtual string Name { get { throw null; } }
public override long Position { get { throw null; } set { } }
public virtual Microsoft.Win32.SafeHandles.SafeFileHandle SafeFileHandle { get { throw null; } }
public override System.IAsyncResult BeginRead(byte[] array, int offset, int numBytes, System.AsyncCallback callback, object? state) { throw null; }
public override System.IAsyncResult BeginWrite(byte[] array, int offset, int numBytes, System.AsyncCallback callback, object? state) { throw null; }
public override System.IAsyncResult BeginRead(byte[] array, int offset, int numBytes, System.AsyncCallback? callback, object? state) { throw null; }
public override System.IAsyncResult BeginWrite(byte[] array, int offset, int numBytes, System.AsyncCallback? callback, object? state) { throw null; }
public override System.Threading.Tasks.Task CopyToAsync(System.IO.Stream destination, int bufferSize, System.Threading.CancellationToken cancellationToken) { throw null; }
protected override void Dispose(bool disposing) { }
public override System.Threading.Tasks.ValueTask DisposeAsync() { throw null; }
Expand Down Expand Up @@ -5475,8 +5475,8 @@ protected Stream() { }
public abstract long Position { get; set; }
public virtual int ReadTimeout { get { throw null; } set { } }
public virtual int WriteTimeout { get { throw null; } set { } }
public virtual System.IAsyncResult BeginRead(byte[] buffer, int offset, int count, System.AsyncCallback callback, object? state) { throw null; }
public virtual System.IAsyncResult BeginWrite(byte[] buffer, int offset, int count, System.AsyncCallback callback, object? state) { throw null; }
public virtual System.IAsyncResult BeginRead(byte[] buffer, int offset, int count, System.AsyncCallback? callback, object? state) { throw null; }
public virtual System.IAsyncResult BeginWrite(byte[] buffer, int offset, int count, System.AsyncCallback? callback, object? state) { throw null; }
public virtual void Close() { }
public void CopyTo(System.IO.Stream destination) { }
public virtual void CopyTo(System.IO.Stream destination, int bufferSize) { }
Expand Down

0 comments on commit 0790041

Please sign in to comment.