This is an automated email from the ASF dual-hosted git repository.
curth pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/main by this push:
new e411e0e211 GH-41602: [C#] Resolve build warnings (#41645)
e411e0e211 is described below
commit e411e0e211206dd7040668dac08ae935e8037aa9
Author: Curt Hagenlocher <[email protected]>
AuthorDate: Tue May 14 12:52:59 2024 -0700
GH-41602: [C#] Resolve build warnings (#41645)
### What changes are included in this PR?
Adds annotations or suppressions to disable build warnings. Configures
projects to produce an error on warnings.
### Are these changes tested?
Changes are covered by existing tests.
Closes #41602
* GitHub Issue: #41602
Authored-by: Curt Hagenlocher <[email protected]>
Signed-off-by: Curt Hagenlocher <[email protected]>
---
csharp/Directory.Build.props | 4 ++-
csharp/feather.png | Bin 0 -> 40042 bytes
csharp/src/Apache.Arrow/Arrays/BinaryArray.cs | 4 +--
csharp/src/Apache.Arrow/Arrays/Decimal256Array.cs | 14 +++++-----
.../src/Apache.Arrow/Memory/NativeMemoryManager.cs | 2 ++
.../FlightSqlServerTests.cs | 25 ++++++++---------
.../test/Apache.Arrow.Flight.Tests/FlightTests.cs | 30 ++++++++++-----------
csharp/test/Apache.Arrow.Tests/ArrowArrayTests.cs | 6 ++---
.../test/Apache.Arrow.Tests/DurationArrayTests.cs | 2 +-
9 files changed, 47 insertions(+), 40 deletions(-)
diff --git a/csharp/Directory.Build.props b/csharp/Directory.Build.props
index f6d42241f9..3c06d3cd31 100644
--- a/csharp/Directory.Build.props
+++ b/csharp/Directory.Build.props
@@ -37,12 +37,13 @@
<LangVersion>latest</LangVersion>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>$(CSharpDir)ApacheArrow.snk</AssemblyOriginatorKeyFile>
+ <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<!-- NuGet properties -->
<PropertyGroup>
<Authors>The Apache Software Foundation</Authors>
- <PackageIconUrl>https://www.apache.org/images/feather.png</PackageIconUrl>
+ <PackageIcon>feather.png</PackageIcon>
<!-- We can't use PackageLicenseExpression; the license file also contains
3rd-party notices. -->
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
<PackageProjectUrl>https://arrow.apache.org/</PackageProjectUrl>
@@ -55,6 +56,7 @@
<ItemGroup Condition="'$(IsPackable)' == 'true'">
<Content Include="$(RepoRoot)LICENSE.txt" Pack="true" PackagePath="" />
+ <Content Include="$(CSharpDir)/feather.png" Link="feather.png" Pack="true"
PackagePath="\" />
</ItemGroup>
</Project>
diff --git a/csharp/feather.png b/csharp/feather.png
new file mode 100644
index 0000000000..7b596e6683
Binary files /dev/null and b/csharp/feather.png differ
diff --git a/csharp/src/Apache.Arrow/Arrays/BinaryArray.cs
b/csharp/src/Apache.Arrow/Arrays/BinaryArray.cs
index 0c84fa2be2..bd5d9315e9 100644
--- a/csharp/src/Apache.Arrow/Arrays/BinaryArray.cs
+++ b/csharp/src/Apache.Arrow/Arrays/BinaryArray.cs
@@ -383,8 +383,8 @@ namespace Apache.Arrow
int ICollection<byte[]>.Count => Length;
bool ICollection<byte[]>.IsReadOnly => true;
- void ICollection<byte[]>.Add(byte[]? item) => throw new
NotSupportedException("Collection is read-only.");
- bool ICollection<byte[]>.Remove(byte[]? item) => throw new
NotSupportedException("Collection is read-only.");
+ void ICollection<byte[]>.Add(byte[] item) => throw new
NotSupportedException("Collection is read-only.");
+ bool ICollection<byte[]>.Remove(byte[] item) => throw new
NotSupportedException("Collection is read-only.");
void ICollection<byte[]>.Clear() => throw new
NotSupportedException("Collection is read-only.");
bool ICollection<byte[]>.Contains(byte[] item)
diff --git a/csharp/src/Apache.Arrow/Arrays/Decimal256Array.cs
b/csharp/src/Apache.Arrow/Arrays/Decimal256Array.cs
index fa6f765475..52bfb9eb20 100644
--- a/csharp/src/Apache.Arrow/Arrays/Decimal256Array.cs
+++ b/csharp/src/Apache.Arrow/Arrays/Decimal256Array.cs
@@ -13,6 +13,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+#nullable enable
+
using System;
using System.Collections;
using System.Collections.Generic;
@@ -23,7 +25,7 @@ using Apache.Arrow.Types;
namespace Apache.Arrow
{
- public class Decimal256Array : FixedSizeBinaryArray,
IReadOnlyList<SqlDecimal?>, IReadOnlyList<string>
+ public class Decimal256Array : FixedSizeBinaryArray,
IReadOnlyList<SqlDecimal?>, IReadOnlyList<string?>
{
public class Builder : BuilderBase<Decimal256Array, Builder>
{
@@ -178,7 +180,7 @@ namespace Apache.Arrow
return list;
}
- public string GetString(int index)
+ public string? GetString(int index)
{
if (IsNull(index))
{
@@ -230,10 +232,10 @@ namespace Apache.Arrow
}
}
- int IReadOnlyCollection<string>.Count => Length;
- string? IReadOnlyList<string>.this[int index] => GetString(index);
+ int IReadOnlyCollection<string?>.Count => Length;
+ string? IReadOnlyList<string?>.this[int index] => GetString(index);
- IEnumerator<string> IEnumerable<string>.GetEnumerator()
+ IEnumerator<string?> IEnumerable<string?>.GetEnumerator()
{
for (int index = 0; index < Length; index++)
{
@@ -241,6 +243,6 @@ namespace Apache.Arrow
}
}
- IEnumerator IEnumerable.GetEnumerator() =>
((IEnumerable<string>)this).GetEnumerator();
+ IEnumerator IEnumerable.GetEnumerator() =>
((IEnumerable<string?>)this).GetEnumerator();
}
}
diff --git a/csharp/src/Apache.Arrow/Memory/NativeMemoryManager.cs
b/csharp/src/Apache.Arrow/Memory/NativeMemoryManager.cs
index 8f0210b282..d42ee5279e 100644
--- a/csharp/src/Apache.Arrow/Memory/NativeMemoryManager.cs
+++ b/csharp/src/Apache.Arrow/Memory/NativeMemoryManager.cs
@@ -40,10 +40,12 @@ namespace Apache.Arrow.Memory
_owner = owner;
}
+#pragma warning disable CA2015 // TODO: is this correct?
~NativeMemoryManager()
{
Dispose(false);
}
+#pragma warning restore CA2015
public override unsafe Span<byte> GetSpan()
{
diff --git a/csharp/test/Apache.Arrow.Flight.Sql.Tests/FlightSqlServerTests.cs
b/csharp/test/Apache.Arrow.Flight.Sql.Tests/FlightSqlServerTests.cs
index 4ad5bde087..e5e64b073f 100644
--- a/csharp/test/Apache.Arrow.Flight.Sql.Tests/FlightSqlServerTests.cs
+++ b/csharp/test/Apache.Arrow.Flight.Sql.Tests/FlightSqlServerTests.cs
@@ -14,6 +14,7 @@
// limitations under the License.
#nullable enable
+
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
@@ -65,7 +66,7 @@ public class FlightSqlServerTests
var streamWriter = new MockServerStreamWriter<FlightActionType>();
//When
- await producer.ListActions(streamWriter, new
MockServerCallContext()).ConfigureAwait(false);
+ await producer.ListActions(streamWriter, new MockServerCallContext());
var actions = streamWriter.Messages.ToArray();
Assert.Equal(FlightSqlUtils.FlightSqlActions, actions);
@@ -115,7 +116,7 @@ public class FlightSqlServerTests
[InlineData(typeof(CommandGetImportedKeys), "GetImportedKeysFlightInfo")]
[InlineData(typeof(CommandGetCrossReference),
"GetCrossReferenceFlightInfo")]
[InlineData(typeof(CommandGetXdbcTypeInfo), "GetXdbcTypeFlightInfo")]
- public async void EnsureGetFlightInfoIsCorrectlyRoutedForCommand(Type
commandType, string expectedResult)
+ public async Task EnsureGetFlightInfoIsCorrectlyRoutedForCommand(Type
commandType, string expectedResult)
{
//Given
var command = (IMessage) Activator.CreateInstance(commandType)!;
@@ -131,7 +132,7 @@ public class FlightSqlServerTests
[Fact]
- public async void
EnsureAnInvalidOperationExceptionIsThrownWhenACommandIsNotSupportedAndHasNoDescriptor()
+ public async Task
EnsureAnInvalidOperationExceptionIsThrownWhenACommandIsNotSupportedAndHasNoDescriptor()
{
//Given
var producer = new TestFlightSqlSever();
@@ -145,7 +146,7 @@ public class FlightSqlServerTests
}
[Fact]
- public async void
EnsureAnInvalidOperationExceptionIsThrownWhenACommandIsNotSupported()
+ public async Task
EnsureAnInvalidOperationExceptionIsThrownWhenACommandIsNotSupported()
{
//Given
var producer = new TestFlightSqlSever();
@@ -175,7 +176,7 @@ public class FlightSqlServerTests
[InlineData(typeof(CommandGetImportedKeys), "DoGetImportedKeys")]
[InlineData(typeof(CommandGetCrossReference), "DoGetCrossReference")]
[InlineData(typeof(CommandGetXdbcTypeInfo), "DoGetXbdcTypeInfo")]
- public async void EnsureDoGetIsCorrectlyRoutedForADoGetCommand(Type
commandType, string expectedResult)
+ public async Task EnsureDoGetIsCorrectlyRoutedForADoGetCommand(Type
commandType, string expectedResult)
{
//Given
var producer = new TestFlightSqlSever();
@@ -192,7 +193,7 @@ public class FlightSqlServerTests
}
[Fact]
- public async void
EnsureAnInvalidOperationExceptionIsThrownWhenADoGetCommandIsNotSupported()
+ public async Task
EnsureAnInvalidOperationExceptionIsThrownWhenADoGetCommandIsNotSupported()
{
//Given
var producer = new TestFlightSqlSever();
@@ -213,7 +214,7 @@ public class FlightSqlServerTests
[InlineData(SqlAction.CloseRequest,
typeof(ActionClosePreparedStatementRequest), "ClosePreparedStatement")]
[InlineData(SqlAction.CreateRequest,
typeof(ActionCreatePreparedStatementRequest), "CreatePreparedStatement")]
[InlineData("BadCommand", typeof(ActionCreatePreparedStatementRequest),
"Action type BadCommand not supported", true)]
- public async void EnsureDoActionIsCorrectlyRoutedForAnActionRequest(string
actionType, Type actionBodyType, string expectedResponse, bool isException =
false)
+ public async Task EnsureDoActionIsCorrectlyRoutedForAnActionRequest(string
actionType, Type actionBodyType, string expectedResponse, bool isException =
false)
{
//Given
var producer = new TestFlightSqlSever();
@@ -237,19 +238,19 @@ public class FlightSqlServerTests
[InlineData(typeof(CommandPreparedStatementQuery),
"PutPreparedStatementQuery")]
[InlineData(typeof(CommandPreparedStatementUpdate),
"PutPreparedStatementUpdate")]
[InlineData(typeof(CommandGetXdbcTypeInfo), "Command
CommandGetXdbcTypeInfo not supported", true)]
- public async void EnsureDoPutIsCorrectlyRoutedForTheCommand(Type
commandType, string expectedResponse, bool isException = false)
+ public async Task EnsureDoPutIsCorrectlyRoutedForTheCommand(Type
commandType, string expectedResponse, bool isException = false)
{
//Given
var command = (IMessage) Activator.CreateInstance(commandType)!;
var producer = new TestFlightSqlSever();
var descriptor =
FlightDescriptor.CreateCommandDescriptor(command.PackAndSerialize().ToArray());
var recordBatch = new RecordBatch(new Schema(new List<Field>(), null),
System.Array.Empty<Int8Array>(), 0);
- var reader = new MockStreamReader<FlightData>(await
recordBatch.ToFlightData(descriptor).ConfigureAwait(false));
+ var reader = new MockStreamReader<FlightData>(await
recordBatch.ToFlightData(descriptor));
var batchReader = new FlightServerRecordBatchStreamReader(reader);
var mockStreamWriter = new MockServerStreamWriter<FlightPutResult>();
//When
- async Task Act() => await producer.DoPut(batchReader,
mockStreamWriter, new MockServerCallContext()).ConfigureAwait(false);
+ async Task Act() => await producer.DoPut(batchReader,
mockStreamWriter, new MockServerCallContext());
var exception = await Record.ExceptionAsync(Act);
string? actualMessage = isException ? exception?.Message :
mockStreamWriter.Messages[0].ApplicationMetadata.ToStringUtf8();
@@ -271,7 +272,7 @@ public class FlightSqlServerTests
protected override CancellationToken CancellationTokenCore => default;
protected override Metadata ResponseTrailersCore => new();
protected override Status StatusCore { get; set; }
- protected override WriteOptions WriteOptionsCore { get; set; } =
WriteOptions.Default;
+ protected override WriteOptions? WriteOptionsCore { get; set; } =
WriteOptions.Default;
protected override AuthContext AuthContextCore => new("", new
Dictionary<string, List<AuthProperty>>());
}
}
@@ -325,7 +326,7 @@ internal static class MockStreamReaderWriterExtensions
public static async Task<IEnumerable<FlightData>> ToFlightData(this
RecordBatch recordBatch, FlightDescriptor? descriptor = null)
{
var responseStream = new MockFlightServerRecordBatchStreamWriter();
- await
responseStream.WriteRecordBatchAsync(recordBatch).ConfigureAwait(false);
+ await responseStream.WriteRecordBatchAsync(recordBatch);
if (descriptor == null)
{
return responseStream.FlightData;
diff --git a/csharp/test/Apache.Arrow.Flight.Tests/FlightTests.cs
b/csharp/test/Apache.Arrow.Flight.Tests/FlightTests.cs
index ebc38354b5..aac4e42092 100644
--- a/csharp/test/Apache.Arrow.Flight.Tests/FlightTests.cs
+++ b/csharp/test/Apache.Arrow.Flight.Tests/FlightTests.cs
@@ -288,9 +288,9 @@ namespace Apache.Arrow.Flight.Tests
{
var duplexStreamingCall = _flightClient.Handshake();
- await duplexStreamingCall.RequestStream.WriteAsync(new
FlightHandshakeRequest(ByteString.Empty)).ConfigureAwait(false);
- await
duplexStreamingCall.RequestStream.CompleteAsync().ConfigureAwait(false);
- var results = await
duplexStreamingCall.ResponseStream.ToListAsync().ConfigureAwait(false);
+ await duplexStreamingCall.RequestStream.WriteAsync(new
FlightHandshakeRequest(ByteString.Empty));
+ await duplexStreamingCall.RequestStream.CompleteAsync();
+ var results = await
duplexStreamingCall.ResponseStream.ToListAsync();
Assert.Single(results);
Assert.Equal("Done", results.First().Payload.ToStringUtf8());
@@ -303,10 +303,10 @@ namespace Apache.Arrow.Flight.Tests
var duplexStreamingCall =
_flightClient.DoExchange(flightDescriptor);
var expectedBatch = CreateTestBatch(0, 100);
- await
duplexStreamingCall.RequestStream.WriteAsync(expectedBatch).ConfigureAwait(false);
- await
duplexStreamingCall.RequestStream.CompleteAsync().ConfigureAwait(false);
+ await duplexStreamingCall.RequestStream.WriteAsync(expectedBatch);
+ await duplexStreamingCall.RequestStream.CompleteAsync();
- var results = await
duplexStreamingCall.ResponseStream.ToListAsync().ConfigureAwait(false);
+ var results = await
duplexStreamingCall.ResponseStream.ToListAsync();
Assert.Single(results);
ArrowReaderVerifier.CompareBatches(expectedBatch,
results.FirstOrDefault());
@@ -320,11 +320,11 @@ namespace Apache.Arrow.Flight.Tests
var expectedBatch1 = CreateTestBatch(0, 100);
var expectedBatch2 = CreateTestBatch(100, 100);
- await
duplexStreamingCall.RequestStream.WriteAsync(expectedBatch1).ConfigureAwait(false);
- await
duplexStreamingCall.RequestStream.WriteAsync(expectedBatch2).ConfigureAwait(false);
- await
duplexStreamingCall.RequestStream.CompleteAsync().ConfigureAwait(false);
+ await duplexStreamingCall.RequestStream.WriteAsync(expectedBatch1);
+ await duplexStreamingCall.RequestStream.WriteAsync(expectedBatch2);
+ await duplexStreamingCall.RequestStream.CompleteAsync();
- var results = await
duplexStreamingCall.ResponseStream.ToListAsync().ConfigureAwait(false);
+ var results = await
duplexStreamingCall.ResponseStream.ToListAsync();
ArrowReaderVerifier.CompareBatches(expectedBatch1, results[0]);
ArrowReaderVerifier.CompareBatches(expectedBatch2, results[1]);
@@ -338,8 +338,8 @@ namespace Apache.Arrow.Flight.Tests
var expectedBatch = CreateTestBatch(0, 100);
var expectedMetadata = ByteString.CopyFromUtf8("test metadata");
- await duplexStreamingCall.RequestStream.WriteAsync(expectedBatch,
expectedMetadata).ConfigureAwait(false);
- await
duplexStreamingCall.RequestStream.CompleteAsync().ConfigureAwait(false);
+ await duplexStreamingCall.RequestStream.WriteAsync(expectedBatch,
expectedMetadata);
+ await duplexStreamingCall.RequestStream.CompleteAsync();
List<ByteString> actualMetadata = new List<ByteString>();
List<RecordBatch> actualBatch = new List<RecordBatch>();
@@ -358,9 +358,9 @@ namespace Apache.Arrow.Flight.Tests
{
var duplexStreamingCall = _flightClient.Handshake();
- await duplexStreamingCall.RequestStream.WriteAsync(new
FlightHandshakeRequest(ByteString.CopyFromUtf8("Hello"))).ConfigureAwait(false);
- await
duplexStreamingCall.RequestStream.CompleteAsync().ConfigureAwait(false);
- var results = await
duplexStreamingCall.ResponseStream.ToListAsync().ConfigureAwait(false);
+ await duplexStreamingCall.RequestStream.WriteAsync(new
FlightHandshakeRequest(ByteString.CopyFromUtf8("Hello")));
+ await duplexStreamingCall.RequestStream.CompleteAsync();
+ var results = await
duplexStreamingCall.ResponseStream.ToListAsync();
Assert.Single(results);
Assert.Equal("Hello handshake",
results.First().Payload.ToStringUtf8());
diff --git a/csharp/test/Apache.Arrow.Tests/ArrowArrayTests.cs
b/csharp/test/Apache.Arrow.Tests/ArrowArrayTests.cs
index d3032b8d4a..c3c21c412d 100644
--- a/csharp/test/Apache.Arrow.Tests/ArrowArrayTests.cs
+++ b/csharp/test/Apache.Arrow.Tests/ArrowArrayTests.cs
@@ -212,11 +212,11 @@ namespace Apache.Arrow.Tests
// Parameter 'values' must contain four values. The last value must be
distinct from the rest.
private static void TestObjectArrayAsCollection<T, TArray>(TArray
array, T nullValue, IReadOnlyList<T> values)
where T : class
- where TArray : IArrowArray, ICollection<T?>
+ where TArray : IArrowArray, ICollection<T>
{
Assert.NotNull(array);
Assert.Equal(4, values.Count);
- var collection = (ICollection<T?>)array;
+ var collection = (ICollection<T>)array;
Assert.Equal(array.Length, collection.Count);
Assert.Equal(4, collection.Count);
@@ -232,7 +232,7 @@ namespace Apache.Arrow.Tests
Assert.False(collection.Contains(values[3]));
T sentinel = values[2];
- T?[] destArr = { sentinel, sentinel, sentinel, sentinel, sentinel,
sentinel };
+ T[] destArr = { sentinel, sentinel, sentinel, sentinel, sentinel,
sentinel };
collection.CopyTo(destArr, 1);
Assert.Equal(sentinel, destArr[0]);
Assert.Equal(values[0], destArr[1]);
diff --git a/csharp/test/Apache.Arrow.Tests/DurationArrayTests.cs
b/csharp/test/Apache.Arrow.Tests/DurationArrayTests.cs
index 59080d739b..412f67de5f 100644
--- a/csharp/test/Apache.Arrow.Tests/DurationArrayTests.cs
+++ b/csharp/test/Apache.Arrow.Tests/DurationArrayTests.cs
@@ -115,7 +115,7 @@ namespace Apache.Arrow.Tests
Assert.Equal(timeSpan, array.GetTimeSpan(0));
IReadOnlyList<TimeSpan?> asList = array;
- Assert.Equal(1, asList.Count);
+ Assert.Single(asList);
Assert.Equal(timeSpan, asList[0]);
}
}