Skip to content

GH-1901 - Use type name for array types in FormattableType.of(ResolvableType). - #1902

Closed
cwJohnPark wants to merge 1 commit into
spring-projects:mainfrom
cwJohnPark:GH-1901-formattable-array-types
Closed

cwJohnPark wants to merge 1 commit into
spring-projects:mainfrom
cwJohnPark:GH-1901-formattable-array-types

Conversation

@cwJohnPark

Copy link
Copy Markdown
Contributor

Fixes #1901.

FormattableType.of(ResolvableType) built the type name from Class#getName(), which yields the JVM binary name for array types ([B, [Ljava.lang.String;). As the instance is cached under the same key that FormattableType.of(Class) uses, the garbled instance also leaked into Class-based lookups, so the result depended on call order.

This switches to Class#getTypeName(), in line with FormattableType.of(Class). It only differs from Class#getName() for array types, so all other types render as before.

Tests added to FormattableTypeUnitTests:

  • handlesArrayTypesFromResolvableType() covers reference, primitive and multi-dimensional arrays as well as an array used as generic argument.
  • rendersArrayTypesConsistentlyIndependentOfLookupOrder() looks up an array type via ResolvableType first and via Class afterwards. It uses a type not referenced by any other test, so the check does not depend on the test execution order.

Verified with ./mvnw -pl spring-modulith-core -am test and the tests of spring-modulith-observability-core, which renders observed method parameters through this code path.

…Type.of(ResolvableType).

FormattableType.of(ResolvableType) used Class#getName(), which renders array types by their JVM
binary names (e.g. [B or [Ljava.lang.String;). As the instance is cached under the same key that
FormattableType.of(Class) uses, the broken instance also leaked into Class-based lookups, so the
result depended on call order. We now use Class#getTypeName() in line with
FormattableType.of(Class).

Signed-off-by: cwjohnpark <pierrotcw@gmail.com>
odrotbohm pushed a commit that referenced this pull request Oct 1, 2026
…bleType).

FormattableType.of(ResolvableType) used Class#getName(), which renders array types by their JVM binary names (e.g. [B or [Ljava.lang.String;). As the instance is cached under the same key that FormattableType.of(Class) uses, the broken instance also leaked into Class-based lookups, so the result depended on call order. We now use Class#getTypeName() in line with FormattableType.of(Class).

Original pull request: GH-1902
Signed-off-by: cwjohnpark <pierrotcw@gmail.com>
odrotbohm pushed a commit that referenced this pull request Oct 1, 2026
…bleType).

FormattableType.of(ResolvableType) used Class#getName(), which renders array types by their JVM binary names (e.g. [B or [Ljava.lang.String;). As the instance is cached under the same key that FormattableType.of(Class) uses, the broken instance also leaked into Class-based lookups, so the result depended on call order. We now use Class#getTypeName() in line with FormattableType.of(Class).

Original pull request: GH-1902
Signed-off-by: cwjohnpark <pierrotcw@gmail.com>
@odrotbohm odrotbohm closed this Oct 1, 2026
odrotbohm pushed a commit that referenced this pull request Oct 9, 2026
…bleType).

FormattableType.of(ResolvableType) used Class#getName(), which renders array types by their JVM binary names (e.g. [B or [Ljava.lang.String;). As the instance is cached under the same key that FormattableType.of(Class) uses, the broken instance also leaked into Class-based lookups, so the result depended on call order. We now use Class#getTypeName() in line with FormattableType.of(Class).

Original pull request: GH-1902
Signed-off-by: cwjohnpark <pierrotcw@gmail.com>
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.

FormattableType.of(ResolvableType) renders array types using their JVM binary names

2 participants