Skip to content

Make SpecificationItem immutable with toBuilder() #572

Description

@kaklakariada

Goal

Make SpecificationItem fully immutable by replacing its public mutation API with a builder-copy workflow.

Scope

  • Remove the public SpecificationItem.addCoveredId(SpecificationItemId) method as a breaking API change.
  • Add SpecificationItem.toBuilder(), returning an independent builder pre-populated with every item property, including located IDs/ranges, text fields, status, location, relations, tags, and forwarding state.
  • Defensively snapshot all builder-owned collections when building a SpecificationItem, so later builder changes cannot affect an existing item.
  • Preserve the linker’s derived covered-ID behavior: when it must add a missing covered ID, LinkedSpecificationItem replaces its wrapped item with item.toBuilder().addCoveredId(...).build() instead of mutating the original.
  • Update dsn~specification-item to revision 4 and update corresponding implementation and unit-test trace markers.

Acceptance Criteria

  • A toBuilder().build() copy retains all source properties.
  • Changing a copied builder produces a new item and leaves the source unchanged.
  • Mutating a builder after build() does not change the built item’s collections.
  • Linked items continue to expose inferred covered IDs after linking, while the source SpecificationItem remains unchanged.
  • ./oft-self-trace.sh and mvn -T 1C verify pass.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    refactoringCode improvement without behavior change

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions