@@ -172,6 +172,38 @@ public class Discoverable<T extends Number & Comparable<T>> {
172172 assertThat (boundNames ).anyMatch (name -> name .contains ("Comparable" ));
173173 }
174174
175+ @ Test
176+ void genericTypeNameShouldIncludeModule () {
177+ // Regression: visitDeclared was constructing TypeNames with Optional.empty() module,
178+ // causing generic raw types to not match descriptors registered with a JPMS module.
179+ final var source = JavaFileObjects .forSourceString ("build.codemodel.jdk.example.Wrapper" , """
180+ package build.codemodel.jdk.example;
181+ import java.util.List;
182+ public class Wrapper {
183+ public List<String> items;
184+ }
185+ """ );
186+ final var codeModel = JdkInitializerTests .runInternal (
187+ new JdkInitializer (List .of (), List .of (), List .of (source )));
188+
189+ final var naming = codeModel .getNameProvider ();
190+ final var typeName = naming .getTypeName (Optional .empty (), "build.codemodel.jdk.example.Wrapper" );
191+ final var field = codeModel .getTypeDescriptor (typeName ).orElseThrow ()
192+ .traits (FieldDescriptor .class ).findFirst ().orElseThrow ();
193+
194+ final var generic = (GenericTypeUsage ) field .type ();
195+
196+ // The raw type must carry the java.base module
197+ final var javaBase = naming .getModuleName ("java.base" );
198+ final var expectedListName = naming .getTypeName (javaBase , "java.util.List" );
199+ assertThat (generic .typeName ()).isEqualTo (expectedListName );
200+
201+ // The type argument (String) must also carry java.base
202+ final var stringArg = (NamedTypeUsage ) generic .parameters ().findFirst ().orElseThrow ();
203+ final var expectedStringName = naming .getTypeName (javaBase , "java.lang.String" );
204+ assertThat (stringArg .typeName ()).isEqualTo (expectedStringName );
205+ }
206+
175207 @ Test
176208 void shouldDiscoverGenericMethodTypeParameter () {
177209 final var source = JavaFileObjects .forSourceString ("Discoverable" , """
0 commit comments