Generated metamodel contains invalid import when using generics
Description
Given the following sources
the generated metamodel ChildA_ contains an invalid import
which prevents compilation.
By experimenting i found that
ChildA needs to be in a different package than Parent for this bug to occur
declaring ChildA as ChildA<A, B extends ChildB<A>> (without extends Parent) doesn’t reproduce the bug
when ChildB declares multiple type parameters (all specified as a wildcard in ChildA), the generated import changes, e.g. when ChildB declares type parameters <A, B, C> the resulting import will be
unfortunately, the pull request only addresses trailing >, but as mentioned at the end of the issue, thats not the only problem. a real “quick and dirty” fix would at least require removing (?:,\?)*>$.
Čedomir Igaly January 18, 2024 at 5:13 PM
Edited
I’ve created quick&dirty fix for this problem in pull request 7716 Part of source code that is handling imports is full of things that have dirty smell, so I guess this one is not worse than rest.
Unfortunately, there are more of such “features” hidden in metamodel generator
Given the following sources
the generated metamodel
ChildA_
contains an invalid importwhich prevents compilation.
By experimenting i found that
ChildA
needs to be in a different package thanParent
for this bug to occurdeclaring
ChildA
asChildA<A, B extends ChildB<A>>
(withoutextends Parent
) doesn’t reproduce the bugwhen
ChildB
declares multiple type parameters (all specified as a wildcard inChildA
), the generated import changes, e.g. whenChildB
declares type parameters<A, B, C>
the resulting import will beJava 21, hibernate-jpamodelgen 6.4.1.Final, Maven 3.8.6