minor
#29380
Context-sensitive auto-numbering fails if the context and the numbered object are created within a single transaction
When creating an object with a context-aware sequence default (SequenceDefaultProvider or NumberHandlerDefaultProvider with <dynamic-sequence-name class="com.top_logic.element.structured.util.ContextAwareSequenceName"/>), the numbering process fails with a NullPointerException if the context (the object that distinguishes the sequence) and the numbered object are created within the same transaction.
Scenario
A container (e.g., a project) and an auto-numbered element contained within it (e.g., a ticket with a project-local sequential number) are created in a single commit—as observed via the Instance Editor, which creates the container and its child in a single step; More generally, this occurs whenever the context object has not yet been persisted at the time of saving (e.g., creation via a grid row).
Cause
The number is not assigned until the commit (createForUI == false). ContextAwareSequenceName.getSequenceName(context) returns the context object itself. SequenceIdGenerator.addNames(...) uses this to form the sequence name’s discriminator via ((TLObject) id).tId().asString(). If the context is newly created in the same commit and is therefore still transient, tId() == null, and the call to asString() results in a NullPointerException. This causes the entire save operation to be rolled back.
Stack trace (excerpt):
java.lang.NullPointerException: Cannot invoke
"com.top_logic.dob.identifier.ObjectKey.asString()" because the return value of
"com.top_logic.model.TLObject.tId()" is null
at com.top_logic.element.structured.util.SequenceIdGenerator.addNames(SequenceIdGenerator.java:177)
at com.top_logic.element.structured.util.SequenceDefaultProvider.createDefault(SequenceDefaultProvider.java:136)
at com.top_logic.model.factory.TLFactory.setupDefaultValues(TLFactory.java:135)
at com.top_logic.element.layout.grid.GridComponent.storeRowValues(GridComponent.java:1427)
Expectation
Context-dependent numbering should also work when the context object is created within the same transaction. Since the number is not assigned until commit anyway, the context object already has an ID at that point; so the discriminator should only be resolved once an ID has been assigned to the context object. Alternatively (or in the event that the context cannot, in principle, receive an ID), a meaningful error message should be displayed instead of a NullPointerException.