Repository navigation
Fix #6397: Preserve buffered properties in immutable creator-based builders - #6407
Conversation
1 similar comment
|
Something wrong with this pr... ? |
|
@wozhenbang2004 Could you please enable "Allow edits from maintainers" on this PR? I'd like to push a small update directly: Thanks! |
|
Suggestion for a small refactoring to avoid the // PropertyValue (base)
/**
* Method called to assign stored value to given instance, returning the
* instance to use from then on: for (immutable) Builders this may differ
* from the one passed in. Default implementation calls {@link #assign} and
* returns the original instance.
*
* @since 3.4
*/
public Object assignAndReturn(DeserializationContext ctxt, Object bean) throws JacksonException {
assign(ctxt, bean);
return bean;
}
// PropertyValue.Regular
@Override
public Object assignAndReturn(DeserializationContext ctxt, Object bean) throws JacksonException {
return _property.setAndReturn(ctxt, bean, value);
}and then in for (PropertyValue pv = buffer.buffered(); pv != null; pv = pv.next) {
if (buffer._mayRebind) {
bean = pv.assignAndReturn(ctxt, bean);
} else {
pv.assign(ctxt, bean);
}
}The |
|
@cowtowncoder Maintainer edits are enabled now. Thanks for taking care of the update! |
- Remove VERSION/CREDITS entries: 3.3.0 is already released and this fix targets 3.x (3.4.0, no release-note entries yet) - Make ImmutableBuilderWithCreator6397Test extend DatabindTestUtil - Cover all creator.build() paths: creator property last or missing (END_OBJECT), short array (END_ARRAY), and @JsonUnwrapped builder Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Add `PropertyBasedCreator.build(ctxt, buffer, useSetterReturn)`; builder deserializers pass `true`, the 2-arg variant keeps ignoring setter return values. No longer depends on `PropertyValueBuffer._mayRebind` (an Object Id concern, [databind#5909]), so buffers created via the deprecated `startBuilding()` overloads are handled too - Replace `instanceof PropertyValue.Regular` check with overridable `PropertyValue.assignAndReturn()` (default: `assign()` + return bean) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Code Review ✅ Approved🟡 Medium risk · Applying setter-return replacements during buffered deserialization could produce incorrect final objects if a builder setter returns an unexpected instance. Fixes buffered regular property assignment on immutable creator-based builders so the replacement instance returned by a setter is carried forward instead of being dropped when the value is read before the creator runs. No issues found. VerificationRules No rules evaluated Functional validation Not enabledFor more verification details, comment OptionsAuto-apply is off → Gitar will not commit updates to this branch. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source |
Fixes #6397.
An immutable builder can return a replacement instance from a setter. When the value is read before the creator is invoked, applying the buffered assignment currently drops that returned instance.
Carry the replacement forward for buffered regular properties on the builder path. Ordinary bean assignment and buffered any-setter, merge, and map entries keep their current behavior.
The regression covers array-shaped and object-shaped input and verifies that a mutable bean ignores a setter return value. The two immutable-builder cases fail on the unmodified implementation.
Maven
clean verifyon JDK 21 completed with 7,775 tests passed and 1 skipped after merging the current3.xbase.