Skip to content

Fix isUnchangedStructure always returning false#262

Merged
fh-ms merged 5 commits intomainfrom
fix-legacy-handling-logic
Apr 30, 2026
Merged

Fix isUnchangedStructure always returning false#262
fh-ms merged 5 commits intomainfrom
fix-legacy-handling-logic

Conversation

@fh-ms
Copy link
Copy Markdown
Contributor

@fh-ms fh-ms commented Apr 30, 2026

Summary

  • PersistenceLegacyTypeMappingResult.isUnchangedStructure compared mapping.get(legacyMember) — a Similarity<PersistenceTypeDefinitionMember> — directly against currentMember via !=. The two are unrelated types, so the check was always true and the method always returned false on the first iteration.
  • The unchanged-structure fast path in PersistenceLegacyTypeHandlerCreator therefore 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.
  • Fix: extract targetElement() from the similarity (with a null guard) before comparing — same pattern already used in PersistenceLegacyTypeHandlerCreator.deriveEnumOrdinalMapping.

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.
@fh-ms fh-ms requested a review from zdenek-jonas April 30, 2026 12:41
@fh-ms fh-ms added the bug Something isn't working label Apr 30, 2026
@fh-ms fh-ms requested a review from Copilot April 30, 2026 12:41
@fh-ms fh-ms added this to the 4.1.0 milestone Apr 30, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 a Similarity instance 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.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 isUnchangedStructure to compare Similarity.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.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 (typeName equality) with equalsStructure(...).

💡 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.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 against Similarity.targetElement() (with null guard) and to validate member compatibility via equalsLayout(...) instead of the previous always-false check.
  • Introduce equalsLayout(...) / equalLayout(...) / equalLayouts(...) on PersistenceTypeDescriptionMember to 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.

@fh-ms fh-ms merged commit 639ecdc into main Apr 30, 2026
17 checks passed
@fh-ms fh-ms deleted the fix-legacy-handling-logic branch April 30, 2026 16:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants