GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — add support for generics in Arrays and fix initialization of multidimensional arrays by hduelme · Pull Request #4050 · mapstruct/mapstruct

Conversation

@hduelme

@hduelme hduelme commented May 9, 2026

Copy link
Copy Markdown
Contributor

While reviewing #4045 and looking for places where objects are initialized, I came across generics with arrays.

Bug fixes included in this PR:

  1. Creation of arrays with generics
    Turns out generics are not allowed on an array constructor. MapStruct generates:
    return new CustomerGenerics<String>[0];
    I centralized array initialization with size handling in constructArrayType nd removed the generics there. The same issue existed when mapping Streams to arrays.

  2. Missing generics on method creation
    MapStruct currently drops generics on generated methods.
    From:
    CustomerGenerics<String>[] array(CustomerGenerics<String>[] a);
    it generates:
    public CustomerGenerics[] array(CustomerGenerics[] a) {
    I fixed this by reading the generics from the first component type that is not an array. This also required implementing withoutBounds() and replaceSuperBoundWith() for arrays

  3. Wrong creation of default arrays for multidimensional arrays
    Currently MapStruct writes the size in the last brackets, but it needs to be in the first:
    return new byte[][0];

  4. Multidimensional arrays do not work correctly with generics or varargs
    I fixed the implementation in Type.ftl : first the base type, then the generics, then the array dimensions, and finally the last array or varargs declaration.

I added tests for my changes to the existing test suite. It might make sense to move Issue895Test to the array package, since it directly tests whether multidimensional arrays work correctly.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
hduelme and others added 3 commits May 9, 2026 22:46
@hduelme
add support for generics in Arrays and fix initialization of multidim…
9574501
…ensional arrays
@filiphr
polish
779b2b9
@filiphr
fix whitespace
a9969a4
@filiphr

filiphr commented May 14, 2026

Copy link
Copy Markdown
Member

@hduelme nice catch and nice fix. I did a small polish, have a look and let me know if you don't agree with it

hduelme reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@filiphr filiphr added the enhancement label May 14, 2026
@filiphr filiphr added this to the 1.7.0.Beta2 milestone May 14, 2026
@hduelme

hduelme commented May 14, 2026

Copy link
Copy Markdown
Contributor Author

@filiphr I agree, your polished version shows the difference between array types and none-array types much more clearly. The missing s was a copy-paste error on my part.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@filiphr
filiphr merged commit e038070 into mapstruct:main May 14, 2026
9 checks passed

Uh oh!

There was an error while loading. Please reload this page.

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

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

enhancement

Projects

None yet

Milestone

1.7.0.Beta2

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@hduelme @filiphr
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.