Skip to content

TBoldObjectReference accepts locators from another TBoldSystem #42

Description

@bero

Single-role references accept a locator that belongs to another TBoldSystem, while the list side (TBoldObjectList.CheckAdd/CheckReplace) rejects it. Found during a full-history code review (finding M2). Not a regression — the guard has been missing on the single-reference side since the original BoldSoft code.

Symptom

Assigning a single-role association across two live TBoldSystem instances (e.g. A1.next := A2 where A1 and A2 live in different systems) is silently accepted. The stored locator's ID belongs to the other system's database, so persisting the link writes a foreign ID — a dangling-link corruption once the two databases diverge.

Root cause

  1. TBoldObjectList.CheckAdd/CheckReplace in Source/ObjectSpace/BORepresentation/BoldSystem.pas guard multilinks with OwnedByObject and (BoldSystem <> NewLocator.BoldSystem).
  2. The single-reference counterpart TBoldObjectReference.CanSetLocator only calls VerifyClass — it never compares systems, so cross-system locators pass validation and are stored.

Fix

  • TBoldObjectReference.CanSetLocator: after VerifyClass, reject when Assigned(NewLocator) and OwnedByObject and (BoldSystem <> NewLocator.BoldSystem), setting a failure reason so SetLocator's existing BoldRaiseLastFailure turns it into a raised exception — same mechanism as the list side.
  • BoldCoreConsts: new sCannotLinkAcrossSystems message constant.
  • Test: TestSetLocatorRejectsCrossSystemObject in UnitTest/Code/ObjectSpace/Test.BoldSystem.pas — two live systems sharing one SystemTypeInfoHandle; verifies the assignment raises and nothing is stored (red before the fix, green after).

Files changed

  • Source/ObjectSpace/BORepresentation/BoldSystem.pas
  • Source/ObjectSpace/Core/BoldCoreConsts.pas
  • UnitTest/Code/ObjectSpace/Test.BoldSystem.pas

Testing

  • New regression test fails without the guard ("Method did not throw any exceptions.") and passes with it
  • Full suite: 2120 found / 2118 pass / 0 failures — no legitimate usage broken

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions