Skip to content

Commit c871e23

Browse files
authored
Fix/remove TODO-NULLABLEs (#44300)
* Fix/remove TODO-NULLABLEs * remove redundant ! * apply Jozkee's feedback * address feedback
1 parent 7b93881 commit c871e23

File tree

19 files changed

+34
-41
lines changed

19 files changed

+34
-41
lines changed

src/libraries/System.ComponentModel.Annotations/src/System/ComponentModel/DataAnnotations/CompareAttribute.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ public override string FormatErrorMessage(string name) =>
6060
var display = attributes.OfType<DisplayAttribute>().FirstOrDefault();
6161
if (display != null)
6262
{
63-
// TODO-NULLABLE: This will return null if [DisplayName] is specified but no Name has been defined - probably a bug.
64-
// Should fall back to OtherProperty in this case instead.
6563
return display.GetName();
6664
}
6765

src/libraries/System.ComponentModel.Annotations/src/System/ComponentModel/DataAnnotations/ValidationAttribute.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,6 @@ private void SetResourceAccessorByPropertyLookup()
273273
_errorMessageResourceType.FullName));
274274
}
275275

276-
277-
// TODO-NULLABLE: If the user-provided resource returns null, an ArgumentNullException is thrown - should probably throw a better exception
278276
_errorMessageResourceAccessor = () => (string)property.GetValue(null, null)!;
279277
}
280278

src/libraries/System.ComponentModel.Annotations/src/System/ComponentModel/DataAnnotations/Validator.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ public static bool TryValidateObject(object instance, ValidationContext validati
137137
throw new ArgumentNullException(nameof(instance));
138138
}
139139

140-
// TODO-NULLABLE: null validationContext isn't supported (GetObjectValidationErrors will throw), remove that check
141140
if (validationContext != null && instance != validationContext.ObjectInstance)
142141
{
143142
throw new ArgumentException(SR.Validator_InstanceMustMatchValidationContextInstance, nameof(instance));

src/libraries/System.Data.Odbc/src/System/Data/Odbc/OdbcConnectionOpen.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public override string ServerVersion
3232
{
3333
get
3434
{
35-
// TODO-NULLABLE: This seems like it returns null if the connection is open, whereas the docs say it should throw
35+
// https://github.com/dotnet/runtime/issues/44289: This seems like it returns null if the connection is open, whereas the docs say it should throw
3636
// InvalidOperationException
3737
return OuterConnection.Open_GetServerVersion()!;
3838
}

src/libraries/System.Data.OleDb/src/ColumnBinding.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -948,8 +948,7 @@ internal OleDbDataReader Value_HCHAPTER()
948948
Debug.Assert(NativeDBType.HCHAPTER == DbType, "Value_HCHAPTER");
949949
Debug.Assert(DBStatus.S_OK == StatusValue(), "Value_HCHAPTER");
950950

951-
// TODO-NULLABLE: This shouldn't return null
952-
return DataReader().ResetChapter(IndexForAccessor, IndexWithinAccessor, RowBinding, ValueOffset)!;
951+
return DataReader().ResetChapter(IndexForAccessor, IndexWithinAccessor, RowBinding, ValueOffset);
953952
}
954953

955954
private sbyte Value_I1()

src/libraries/System.Data.OleDb/src/OleDbCommand.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,6 @@ private int ExecuteCommandText(out object executeResult)
818818
RuntimeHelpers.PrepareConstrainedRegions();
819819
try
820820
{
821-
// TODO-NULLABLE: Code below seems to assume that bindings will always be non-null
822821
if (null != bindings)
823822
{ // parameters may be suppressed
824823
rowbinding = bindings.RowBinding();

src/libraries/System.Data.OleDb/src/OleDbConnectionFactory.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ public override DbProviderFactory ProviderFactory
3333

3434
protected override DbConnectionInternal CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, object poolGroupProviderInfo, DbConnectionPool? pool, DbConnection? owningObject)
3535
{
36-
// TODO-NULLABLE: owningObject may actually be null (see DbConnectionPool.CreateObject), in which case this will throw...
37-
DbConnectionInternal result = new OleDbConnectionInternal((OleDbConnectionString)options, (OleDbConnection)owningObject!);
36+
DbConnectionInternal result = new OleDbConnectionInternal((OleDbConnectionString)options, (OleDbConnection?)owningObject);
3837
return result;
3938
}
4039

src/libraries/System.Data.OleDb/src/OleDbConnectionInternal.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ internal void EnlistTransactionInternal(SysTx.Transaction? transaction)
385385
using (IDBInfoWrapper wrapper = IDBInfo())
386386
{
387387
UnsafeNativeMethods.IDBInfo dbInfo = wrapper.Value;
388-
// TODO-NULLABLE: check may not be necessary (and thus method may return non-nullable)
388+
// https://github.com/dotnet/runtime/issues/44288: check may not be necessary (and thus method may return non-nullable)
389389
if (null == dbInfo)
390390
{
391391
return null;

src/libraries/System.Data.OleDb/src/OleDbDataReader.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -951,22 +951,23 @@ protected override DbDataReader GetDbDataReader(int ordinal)
951951
return GetData(ordinal);
952952
}
953953

954-
internal OleDbDataReader? ResetChapter(int bindingIndex, int index, RowBinding rowbinding, int valueOffset)
954+
internal OleDbDataReader ResetChapter(int bindingIndex, int index, RowBinding rowbinding, int valueOffset)
955955
{
956956
return GetDataForReader(_metadata![bindingIndex + index].ordinal, rowbinding, valueOffset);
957957
}
958958

959-
private OleDbDataReader? GetDataForReader(IntPtr ordinal, RowBinding rowbinding, int valueOffset)
959+
private OleDbDataReader GetDataForReader(IntPtr ordinal, RowBinding rowbinding, int valueOffset)
960960
{
961961
UnsafeNativeMethods.IRowsetInfo rowsetInfo = IRowsetInfo();
962962
UnsafeNativeMethods.IRowset? result;
963963
OleDbHResult hr;
964964
hr = rowsetInfo.GetReferencedRowset((IntPtr)ordinal, ref ODB.IID_IRowset, out result);
965965

966966
ProcessResults(hr);
967+
// Per docs result can be null only when hr is DB_E_NOTAREFERENCECOLUMN which in most of the cases will cause the exception in ProcessResult
967968

968969
OleDbDataReader? reader = null;
969-
// TODO: Not sure if GetReferenceRowset above actually returns null, calling code seems to assume it doesn't
970+
970971
if (null != result)
971972
{
972973
// only when the first datareader is closed will the connection close
@@ -983,6 +984,7 @@ protected override DbDataReader GetDbDataReader(int ordinal)
983984
_connection.AddWeakReference(reader, OleDbReferenceCollection.DataReaderTag);
984985
}
985986
}
987+
986988
return reader;
987989
}
988990

@@ -1022,8 +1024,9 @@ public override Type GetFieldType(int index)
10221024
{
10231025
if (null != _metadata)
10241026
{
1025-
// TODO-NULLABLE: Should throw if null (empty), though it probably doesn't happen
1026-
return _metadata[index].type.dataType!;
1027+
Type? fieldType = _metadata[index].type.dataType;
1028+
Debug.Assert(fieldType != null);
1029+
return fieldType;
10271030
}
10281031
throw ADP.DataReaderNoData();
10291032
}
@@ -2273,7 +2276,6 @@ internal void DumpToSchemaTable(UnsafeNativeMethods.IRowset? rowset)
22732276
using (OleDbDataReader dataReader = new OleDbDataReader(_connection, _command, int.MinValue, 0))
22742277
{
22752278
dataReader.InitializeIRowset(rowset, ChapterHandle.DB_NULL_HCHAPTER, IntPtr.Zero);
2276-
// TODO-NULLABLE: BuildSchemaTableInfo asserts that rowset isn't null, but doesn't do anything with it
22772279
dataReader.BuildSchemaTableInfo(rowset!, true, false);
22782280

22792281
hiddenColumns = GetPropertyValue(ODB.DBPROP_HIDDENCOLUMNS);

src/libraries/System.Data.OleDb/src/UnsafeNativeMethods.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ System.Data.OleDb.OleDbHResult GetProperties(
723723
System.Data.OleDb.OleDbHResult GetReferencedRowset(
724724
[In] IntPtr iOrdinal,
725725
[In] ref Guid riid,
726-
[Out, MarshalAs(UnmanagedType.Interface)] out IRowset ppRowset);
726+
[Out, MarshalAs(UnmanagedType.Interface)] out IRowset? ppRowset);
727727

728728
//[PreserveSig]
729729
//int GetSpecification(/*deleted parameter signature*/);

0 commit comments

Comments
 (0)