Open ThomasBarnekow opened 3 years ago
Good catch. Happy to accept a PR on this!
@twsouthwick, this is generated code. Not sure whether anybody outside of Microsoft can help in this case.
@twsouthwick, are you addressing this? As I said above, this is generated code, so the code generator will have to be fixed.
The change needed:
[DisallowNull]
We'll try to get that in for 2.14
Description
The
Document
property of theMainDocumentPart
is defined as follows:Other subclasses of
OpenXmlPart
(e.g.,WorkbookPart
) define their respective root elements (e.g.,Workbook
) in the same way.Firstly, this is inconsistent with the more generic
RootElement
property ofOpenXmlPart
, which correctly flags nullability:Secondly, when nullability is enabled, the definition suggests that
Document
, for example, will not be null. However, the following unit test demonstrates that this is not the case:You will also see the comment telling ReSharper to disable the
HeuristicUnreachableCode
check after asserting thatmainDocumentPart.Document
is null. Owing to the incorrect nullability, ReSharper believes the assertion will throw and, thus, the next assertion will never be reached. This is not correct, of course.Information
Repro
See the unit test above.
Observed
The nullability of root elements is stated as non-nullable.
Expected
The nullability of root elements should be stated as nullable.