Fix isUnchangedStructure always returning false#262
Conversation
PersistenceLegacyTypeMappingResult.isUnchangedStructure compared mapping.get(legacyMember) — a Similarity<PersistenceTypeDefinitionMember> — directly against currentMember via !=, so the check was always true and the method always returned false on the first iteration. As a result the unchanged-structure fast path in PersistenceLegacyTypeHandlerCreator never fired and every legacy handler went through the translating path, even when the layout was actually unchanged. Extract targetElement() from the similarity (with a null guard) before comparing, matching the existing pattern in PersistenceLegacyTypeHandlerCreator.deriveEnumOrdinalMapping.
There was a problem hiding this comment.
Pull request overview
Fixes the unchanged-structure detection used during legacy type-handler creation so that persisted layouts that haven’t changed can take the fast path instead of always falling back to translating handlers.
Changes:
- Fix
PersistenceLegacyTypeMappingResult.isUnchangedStructure(...)to compare the mapped target member (Similarity.targetElement()) rather than comparing aSimilarityinstance to a member. - Add a null-guard for missing mappings before comparing the mapped target member.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Fixes unchanged-structure detection in legacy type mapping so the legacy handler creator can take the “structure unchanged” fast path instead of always producing translating/wrapping handlers.
Changes:
- Fix
isUnchangedStructureto compareSimilarity.targetElement()(with null guard) against the corresponding current member. - Make type-name comparison null-safe and add a primitive-definition special-case comparison.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Fixes a logic error in PersistenceLegacyTypeMappingResult.isUnchangedStructure that prevented the “unchanged-structure” optimization from ever triggering, causing legacy type handler creation to always take the translating path.
Changes:
- Compare a legacy member’s mapping against the corresponding current member by extracting
Similarity.targetElement()(with a null guard). - Replace the old per-member compatibility check (
typeNameequality) withequalsStructure(...).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
isUnchangedStructure now uses equalsLayout instead of equalsStructure, so refactoring-mapping renames still take the unchanged-structure fast path. equalsLayout mirrors equalsStructure on each subtype but drops the member-name check; equalsStructure is left unchanged.
There was a problem hiding this comment.
Pull request overview
Fixes legacy “unchanged structure” detection so the legacy-handler creation can take the fast path when the persisted member layout truly matches the current layout (e.g., renames without layout changes), avoiding unnecessary translating handlers.
Changes:
- Fix
PersistenceLegacyTypeMappingResult.isUnchangedStructure(...)to compare againstSimilarity.targetElement()(with null guard) and to validate member compatibility viaequalsLayout(...)instead of the previous always-false check. - Introduce
equalsLayout(...)/equalLayout(...)/equalLayouts(...)onPersistenceTypeDescriptionMemberto compare persistent layout while ignoring member simple names. - Add/override
equalsLayout(...)for specific member kinds where layout equality needs specialized logic (primitive definitions, enum constants, complex/variable-length generic members).
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
persistence/persistence/src/main/java/org/eclipse/serializer/persistence/types/PersistenceTypeDescriptionMemberPrimitiveDefinition.java |
Defines layout equality for primitive-definition members based on primitiveDefinition(). |
persistence/persistence/src/main/java/org/eclipse/serializer/persistence/types/PersistenceTypeDescriptionMemberFieldGenericVariableLength.java |
Adds layout equality specialization for variable-length generic members. |
persistence/persistence/src/main/java/org/eclipse/serializer/persistence/types/PersistenceTypeDescriptionMemberFieldGenericComplex.java |
Adds deep layout equality for complex generic members (nested members compared by layout). |
persistence/persistence/src/main/java/org/eclipse/serializer/persistence/types/PersistenceTypeDescriptionMemberEnumConstant.java |
Adds layout equality for enum-constant entries (layout footprint is zero). |
persistence/persistence/src/main/java/org/eclipse/serializer/persistence/types/PersistenceTypeDescriptionMember.java |
Adds equalsLayout plus null-safe/static helpers to compare layout (and sequences by layout). |
persistence/persistence/src/main/java/org/eclipse/serializer/persistence/types/PersistenceLegacyTypeMappingResult.java |
Fixes unchanged-structure check to use Similarity.targetElement() and equalsLayout(...). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
PersistenceLegacyTypeMappingResult.isUnchangedStructurecomparedmapping.get(legacyMember)— aSimilarity<PersistenceTypeDefinitionMember>— directly againstcurrentMembervia!=. The two are unrelated types, so the check was always true and the method always returnedfalseon the first iteration.PersistenceLegacyTypeHandlerCreatortherefore never fired: every legacy handler went through the translating path even when the persisted layout was actually unchanged, producing more expensive handlers than necessary on load.targetElement()from the similarity (with a null guard) before comparing — same pattern already used inPersistenceLegacyTypeHandlerCreator.deriveEnumOrdinalMapping.