Situation
Currently, the method addMyItemIdToCoveringItem in LinkedSpecificationItem.java attempts to modify the list of covered IDs directly on the underlying SpecificationItem object:
private void addMyItemIdToCoveringItem(final LinkedSpecificationItem coveringItem)
{
if (coveringItem.getItem().getCoveredIds() != null
&& !coveringItem.getItem().getCoveredIds().contains(getId()))
{
coveringItem.getItem().getCoveredIds().add(getId());
}
}
However, SpecificationItem is designed to be immutable, and its coveredIds list is wrapped in Collections.unmodifiableList during construction:
// In SpecificationItem.java constructor
this.coveredIds = Collections.unmodifiableList(builder.coveredIds);
This leads to an UnsupportedOperationException when addMyItemIdToCoveringItem is called on a real SpecificationItem (unless the list already contains the ID).
Proposed Solution
The logic for establishing bidirectional links should be moved entirely into the LinkedSpecificationItem or the Linker class. LinkedSpecificationItem already maintains its own links map which should be used to track these relationships.
Specifically:
- Remove
addMyItemIdToCoveringItem from LinkedSpecificationItem.
- Ensure that all necessary linking (including back-links) is handled via
addLinkToItemWithStatus or a similar mechanism that operates on LinkedSpecificationItem objects rather than modifying the base SpecificationItem model.
- Review
LinkedSpecificationItem.getCoveredIds() to ensure it correctly aggregates information from both the base item and any links established during the linking phase, if necessary.
Affected Files
api/src/main/java/org/itsallcode/openfasttrace/api/core/LinkedSpecificationItem.java
api/src/main/java/org/itsallcode/openfasttrace/api/core/SpecificationItem.java (for context)
Situation
Currently, the method
addMyItemIdToCoveringIteminLinkedSpecificationItem.javaattempts to modify the list of covered IDs directly on the underlyingSpecificationItemobject:However,
SpecificationItemis designed to be immutable, and itscoveredIdslist is wrapped inCollections.unmodifiableListduring construction:This leads to an
UnsupportedOperationExceptionwhenaddMyItemIdToCoveringItemis called on a realSpecificationItem(unless the list already contains the ID).Proposed Solution
The logic for establishing bidirectional links should be moved entirely into the
LinkedSpecificationItemor theLinkerclass.LinkedSpecificationItemalready maintains its ownlinksmap which should be used to track these relationships.Specifically:
addMyItemIdToCoveringItemfromLinkedSpecificationItem.addLinkToItemWithStatusor a similar mechanism that operates onLinkedSpecificationItemobjects rather than modifying the baseSpecificationItemmodel.LinkedSpecificationItem.getCoveredIds()to ensure it correctly aggregates information from both the baseitemand any links established during the linking phase, if necessary.Affected Files
api/src/main/java/org/itsallcode/openfasttrace/api/core/LinkedSpecificationItem.javaapi/src/main/java/org/itsallcode/openfasttrace/api/core/SpecificationItem.java(for context)