Skip to content

[Bug]: The public constructors of AttributeValueXHTML leave ExternalObjects or the logger null #98

Closed

Description

@samatstariongroup

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 create ExternalObjects, so the property is null. It has a private setter, so a caller cannot fix it.
  • AttributeValueXHTML() does not set logger, so it is null. Every other attribute value class sets NullLogger<T>.Instance in 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) calls result.AddRange(attributeValue.ExternalObjects) and throws an ArgumentNullException for a spec element that holds a value made with the ILoggerFactory constructor. ReqIFContentExtensions.QueryExternalObjects calls it for every spec element, so one such value makes it fail for the whole content.
  • QueryBase64Payloads loops over ExternalObjects and throws a NullReferenceException for the same value.
  • A value made with the parameterless constructor throws an ArgumentNullException (Parameter 'logger') when it is read with ReadXml / 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 logger to NullLogger<AttributeValueXHTML>.Instance in the parameterless constructor.

Acceptance criteria

  • For each public constructor, ExternalObjects is an empty list and not null.
  • QueryExternalObjects on a spec object that holds a value made with new AttributeValueXHTML(loggerFactory) returns an empty list.
  • ReadXmlAsync on a value made with new AttributeValueXHTML() reads the value (or throws OperationCanceledException when 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions