Repository navigation
Closed
Description
What type of issue is this?
- Bug report
- Feature request
Prerequisites
- I have written a descriptive issue title
- I have verified that I am running the latest version of the reqifsharp
- I have searched open and closed issues to ensure it has not already been reported
Description
The two public constructors of AttributeValueXHTML each leave a field uninitialized (ReqIFSharp/AttributeValue/AttributeValueXHTML.cs, lines 51-65):
AttributeValueXHTML(ILoggerFactory loggerFactory)does not createExternalObjects, so the property isnull. It has a private setter, so a caller cannot fix it.AttributeValueXHTML()does not setlogger, so it isnull. Every other attribute value class setsNullLogger<T>.Instancein its parameterless constructor.
The two internal constructors that the deserializer uses set both, so documents that are read are not affected. Values that an application builds itself are:
SpecElementWithAttributesExtensions.QueryExternalObjects(ReqIFSharp.Extensions) callsresult.AddRange(attributeValue.ExternalObjects)and throws anArgumentNullExceptionfor a spec element that holds a value made with theILoggerFactoryconstructor.ReqIFContentExtensions.QueryExternalObjectscalls it for every spec element, so one such value makes it fail for the whole content.QueryBase64Payloadsloops overExternalObjectsand throws aNullReferenceExceptionfor the same value.- A value made with the parameterless constructor throws an
ArgumentNullException(Parameter 'logger') when it is read withReadXml/ReadXmlAsync. These are internal and the library itself never reads into such an instance, so this only shows in tests (found while adding a cancellation test for [Bug]: THE-ORIGINAL-VALUE of an XHTML attribute value is not read #95).
Proposal
- Set
ExternalObjects = new List<ExternalObject>()in every constructor (or initialize the property where it is declared). - Set
loggertoNullLogger<AttributeValueXHTML>.Instancein the parameterless constructor.
Acceptance criteria
- For each public constructor,
ExternalObjectsis an empty list and notnull. QueryExternalObjectson a spec object that holds a value made withnew AttributeValueXHTML(loggerFactory)returns an empty list.ReadXmlAsyncon a value made withnew AttributeValueXHTML()reads the value (or throwsOperationCanceledExceptionwhen the token is cancelled) instead of throwing because the logger is null.
Steps to Reproduce
var specObject = new SpecObject();
specObject.Values.Add(new AttributeValueXHTML(NullLoggerFactory.Instance) { TheValue = "<xhtml:p>text</xhtml:p>" });
specObject.QueryExternalObjects(); // ArgumentNullException: Value cannot be null. (Parameter 'collection')System Configuration
- reqifsharp version:
development(ReqIFSharp 10.1.2, ReqIFSharp.Extensions 5.2.2) - Environment (Operating system, version and so on): any
- .NET Framework version: netstandard2.0 library
- Additional information: found while working on [Bug]: THE-ORIGINAL-VALUE of an XHTML attribute value is not read #95
Metadata
Metadata
Assignees
Labels
No labels
Activity
[Update] remove references to GitHub issues from code comments
[Add] AttributeValueXHTML.ExtractNormalizedTextFromValue for plain te…