Skip to content

--- ## 🛠️ Fix ImmutablesBuilderProvider superclass handling and nested type resolution#4054

Open
ThomasHumper wants to merge 1 commit into
mapstruct:mainfrom
ThomasHumper:patch-1
Open

--- ## 🛠️ Fix ImmutablesBuilderProvider superclass handling and nested type resolution#4054
ThomasHumper wants to merge 1 commit into
mapstruct:mainfrom
ThomasHumper:patch-1

Conversation

@ThomasHumper
Copy link
Copy Markdown

Here’s a clean PR description you can use:


🛠️ Fix ImmutablesBuilderProvider superclass handling and nested type resolution

Summary

This PR fixes incorrect superclass traversal and improves the resolution of Immutables-generated types in ImmutablesBuilderProvider. It also corrects issues in constructing qualified names for nested types when resolving Immutable implementations.


🔧 Changes

1. Fixed superclass lookup logic

  • TypeElement.getSuperclass() returns a TypeMirror, not a TypeElement

  • Added safe handling for:

    • TypeKind.NONE (e.g. java.lang.Object)
    • DeclaredType casting before recursion
  • Prevents incorrect or unsafe recursive calls in findBuilderInfo

2. Fixed immutable type resolution for nested classes

  • Improved asImmutableElement() to correctly handle nested types
  • Replaced fragile single-level enclosing element handling with a safe hierarchy traversal
  • Properly constructs fully qualified name using $ for nested classes

3. Fixed getTypeElement usage

  • Ensured elementUtils.getTypeElement() is called with String (toString() result), not StringBuilder

🧪 Impact

  • Correctly detects builder information for Immutables-generated implementations
  • Fixes failures when working with nested classes or interfaces
  • Prevents incorrect superclass traversal in type hierarchy resolution
  • Improves robustness of annotation processing phase in MapStruct

⚠️ Notes

  • No functional changes to public APIs
  • Only affects annotation processing internals
  • Safe for backward compatibility

If you want, I can also format this for GitHub (with checkboxes, issue links, or conventional commits style).

@hduelme
Copy link
Copy Markdown
Contributor

hduelme commented May 14, 2026

@ThomasHumper I’m not sure what issue this PR is intended to fix. Could you please add tests that reproduce the actual bug being addressed?

Also, MapStruct enforces custom formatting rules via Checkstyle, so please make sure the PR passes those checks as well.


Your summary description currently states:

Ensured elementUtils.getTypeElement() is called with String (toString() result), not StringBuilder

However, that does not appear to be an actual issue, since elementUtils.getTypeElement() accepts any CharSequence, including StringBuilder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants