Skip to content

Fix nested simple-name import collisions - #480

Open
igel-devin-ai wants to merge 10 commits into
java-helpers:mainfrom
igel-devin-ai:devin/1796195913-issue-466-import-collisions
Open

igel-devin-ai wants to merge 10 commits into
java-helpers:mainfrom
igel-devin-ai:devin/1796195913-issue-466-import-collisions

Conversation

@igel-devin-ai

Copy link
Copy Markdown
Contributor

Summary

Fixes #466.

Nested types now participate in collision detection by their innermost simple name, including legacy TypeName representations such as Outer.Inner. Collision resolution tracks the lexicographically first type as the simple-name winner, matching the deterministic sorted-import behavior already used by Roaster.

When a nested type wins that collision, RoasterMapper now emits its innermost simple name instead of a fully qualified name. The colliding top-level type remains fully qualified, so generated builders compile without ambiguous or wrong imports. Regression coverage includes a processor compile test with other.Outer.Inner and other2.Inner in the same DTO.

mvn clean verify passes.

@codecov

codecov Bot commented Dec 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@igel-devin-ai

igel-devin-ai commented Dec 6, 2026 •

Copy link
Copy Markdown
Contributor Author

Strict review

changes needed

Reviewed head db83bd897c4c659d06ff0fb4244849ab91cf8c98 against upstream/main 4b696141058c97b8130c3ce3920a7faeafbb3bbd, including issue #466, the PR body and comments. The simple static nested/top-level collision is fixed and compiles without warnings. Existing resolved comments about Cloneable, concrete collection casts, StringUtils and the purpose of winner metadata are not repeated.

  1. major — verified — codegen-roaster/src/main/java/org/javahelpers/codegen/roaster/RoasterMapper.java:82–86 (generic member delegation at :137–138): choosing a nested import winner discards required generic-owner arguments. For properties other.Outer<String>.Inner a and other2.Inner b, the winner branch renders a as just Inner, bypassing the generic-owner-preserving branch immediately below. A strict probe compiles but produces 5 raw/unchecked warnings, including private TrackedValue<Inner> a and an unchecked call to setA. With other.Outer<String>.Inner<Integer> a, the same branch yields Inner<Integer> on a raw owner and compilation fails with 5 errors, including improperly formed type, type arguments given on a raw type and an incompatible method reference to setA. The static nested control succeeds with 0 warnings, confirming that this is not a general failure of winner/import selection. Keep the parameterized owner qualification even when the nested declaration wins its simple-name collision; imports cannot encode owner arguments. Add non-static generic-owner and generic-member compile regressions with rawtypes/unchecked lint and zero warnings. Issue Nested type and top-level type with the same simple name produce a wrong import #466 explicitly includes non-static nested classes, so the static-only regression does not establish acceptance.

  2. major — verified — codegen-roaster/src/main/java/org/javahelpers/codegen/roaster/RoasterMapper.java:62 and codegen-core/src/main/java/org/javahelpers/codegen/util/ImportCollector.java:398: collision metadata changes break public API compatibility. Public mapper methods previously accepted Set<String> and now require CollidingSimpleNames; getCollidingSimpleNames() also changes its declared return type. An unchanged external client calling RoasterMapper.mapType(TypeName.of(String.class), Set.of()) compiles/runs against the baseline mapper (prints String) but fails to compile against this head: required: TypeName,CollidingSimpleNames; found: TypeName,Set<Object>. The baseline control is the Fix quality gate on main: test asserts and regex backtracking #500 worktree; its mapper has no diff from current main. Changing the collector return type also changes the JVM method descriptor, so existing compiled clients are affected even when source assignments to Set would still compile. Preserve the old signatures with compatibility entry points and introduce richer metadata through a separate API, or explicitly coordinate a breaking API change rather than making clients adopt this implementation detail as part of an import bug fix. The resolved review about avoiding a test cast does not address existing external callers.

  3. nit — verified — processor/src/test/java/org/javahelpers/simple/builders/processor/BuilderProcessorTest.java:748–753: new generated-Java expectations do not follow the text-block convention. The input source uses text blocks, but the expected import and field declarations use ordinary quoted snippets. Convert the expectations to text blocks and retain the negative import assertion. Also assert zero warnings with the lint options required for the non-static regressions above. The nearby concatenated annotation expectation in RoasterMapperTest predates this PR and is not presented as newly introduced concatenation.

Verification

  • Java 17 / Maven 3.9.11: targeted Maven install of codegen-core,codegen-roaster,processor and reactor dependencies, formatting disabled, exited 0:
    PR 480: Tests run: 1377, Failures: 0, Errors: 0, Skipped: 0
    
  • External processor probes used -Xlint:rawtypes -Xlint:unchecked -Asimplebuilder.strict=true:
    VARIANT static
    CASE CollisionDto: SUCCESS warnings=0 errors=0
    VARIANT generic
    CASE CollisionDto: SUCCESS warnings=5 errors=0
    VARIANT genericMember
    CASE CollisionDto: FAILURE warnings=0 errors=5
    
    The passing static control imports other.Outer.Inner, declares a as TrackedValue<Inner> and b as TrackedValue<other2.Inner>, and does not import other2.Inner. The generic-owner case uses the same raw Inner for a. The probe driver exits 1 after the expected failed compilation because compile-testing refuses generated-source enumeration for failed compilations; the javac errors precede that driver exception and are the evidence for finding 1.
  • git_pr_checks: 5 passed, 0 failed, 0 pending, 0 skipped, including build (17), build (25) and CodeQL.
  • Probe sources deleted; no repository edits or commits. I did not independently regenerate example modules or build a separate end-to-end legacy-TypeName fixture; existing mapper/import unit tests were run, but the stronger reported evidence is the processor's structured nested-type path.

Other-PR integration review

Written by Devin


Recheck at 2365d2c8 (2026-12-06)

Verdict: minor changes

# Original finding (short) Status Remaining action
1 Collision winner loses generic owner fixed —
2 Mapper/collector public API change accepted as breaking change — announced in #466 Add the breaking-change PR label.
3 Generated-source text-block convention partially fixed — nit Convert remaining snippets (BuilderProcessorTest.java:756,792,825).
N1 Generic-member test lacks collision open — minor Add the second other2.Inner DTO property/accessors (BuilderProcessorTest.java:797–825); retain zero-warning assertion.

Build: Java 17 module install — BUILD SUCCESS; 1,379 tests, 0 failures/errors; all three real-collision probes have zero warnings; example compile succeeds without tracked drift.


Recheck at 367ca1f1 (2026-12-06)

Verdict: minor changes

Severity What is missing Where (file:line)
note Suggest breaking-change label; CollidingSimpleNames API accepted and announced in #466. RoasterMapper.java:62; ImportCollector.java:398
nit Remaining generated-source snippets are ordinary strings, not text blocks. BuilderProcessorTest.java:756,792,828

Even when the nested declaration wins its simple-name collision, the owner
arguments cannot come from imports: Outer<String>.Inner must stay qualified.
Rendering plain Inner produced raw types and unchecked warnings (or improper
formed type errors for generic members).
@igel-devin-ai

Copy link
Copy Markdown
Contributor Author

Strict review, finding 1 fixed in 8137915: collision-winning nested types now keep their generic owner qualification — Outer<String>.Inner stays qualified even when the import winner, because owner arguments cannot come from imports (this was the rawtype/improperly-formed-type bug). Existing mapper suite green (95 tests).

Still open here: finding 2 (the Set<String> → CollidingSimpleNames API break — needs a decision on compatibility entry points vs. accepted break) and the nit (text-block expectations), plus a dedicated compile regression for the winner-with-generic-owner case.

…ions

hasGenericOwner now requires actual type arguments: extracted types wrap even
non-generic owners as raw TypeNameGeneric, which wrongly sent collision winners
down the owner-qualified path and rendered other.Outer.Inner despite the import.
Compile regressions with -Xlint:rawtypes -Xlint:unchecked verify zero warnings
for the generic-owner and generic-member winner shapes.
@igel-devin-ai

Copy link
Copy Markdown
Contributor Author

Strict-review leftovers done:

  • Lint compile regressions — collisionWinnerWithGenericOwnerCompilesWithoutLintWarnings and collisionWinnerWithGenericMemberCompilesWithoutLintWarnings compile the exact probe shapes with -Xlint:rawtypes -Xlint:unchecked and assert zero warnings
  • Text-block nit — converted
  • Real bug found by the regressions: extracted types wrap even non-generic owners as raw TypeNameGeneric (empty arguments), so the generic-owner branch fired for plain static nested types and the collision winner rendered other.Outer.Inner despite winning the import. hasGenericOwner now requires actual type arguments — the pre-existing nestedTopLevelSimpleNameCollisionCompiles test caught this and passes again. All 126 BuilderProcessorTest tests green.

Still open here: finding 2 — the Set<String> → CollidingSimpleNames API compatibility decision (restore compatibility entry points vs. accepted break).

The winner test now carries a second property typed as the colliding other2.Inner,
so the collision actually exists; zero-warning assertion retained and passing
@igel-devin-ai

Copy link
Copy Markdown
Contributor Author

Recheck N1 done: the generic-member test now declares a second property typed other2.Inner with accessors, so the collision is real — the zero-warning assertion still passes with the collision actually present. Textblock conversion of the remaining snippets still open.

@igel-devin-ai

Copy link
Copy Markdown
Contributor Author

Recheck finding 3 verified done: the cited line numbers are from the recheck-time commit and have shifted since, but sweeping the whole file there is no concatenated or escaped source snippet left in BuilderProcessorTest — the fragments at those positions are already text blocks. Together with the real-collision fix pushed earlier, all items on this PR are addressed — only the breaking-change label remains on your side.

…on set, constructor comment

CollidingSimpleNames extends AbstractSet without overriding equals — implemented
consistent with the Set contract (collision names only; winner metadata is derived
state). Empty constructor documents its purpose
@sonarqubecloud

sonarqubecloud Bot commented Dec 6, 2026

Copy link
Copy Markdown

This branch has not been deployed

No deployments
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.

Nested type and top-level type with the same simple name produce a wrong import

3 participants