Skip to content

Use immutable map for static cache in TypeDescriptor#36813

Open
kilink wants to merge 1 commit into
spring-projects:mainfrom
kilink:type-descriptor-immutable-cache
Open

Use immutable map for static cache in TypeDescriptor#36813
kilink wants to merge 1 commit into
spring-projects:mainfrom
kilink:type-descriptor-immutable-cache

Conversation

@kilink
Copy link
Copy Markdown
Contributor

@kilink kilink commented May 18, 2026

Switch to Map.of for the static commonTypesCache field for immutability.

The rationale for this change is one of hygiene (the read-only map should be immutable), and the fact that the immutable collections added in Java 9 are "trusted" by the JVM and therefore can be constant folded (see a similar JDK issue here where legacy code is being switched the modern immutable collections). I don't have any benchmark supporting any claim in that area, and it would be workload dependent obviously, but it seems like one of those worthwhile changes regardless. If there's alignment there are likely a few other places in spring that could be modernized in this respect.

Note that The valueOf static factory couldn't be used here since it tries to read from the static commonTypesCache field, which with this change wouldn't be initialized yet.

Switch to Map.of for the static commonTypesCache field for immutability.

Signed-off-by: Patrick Strawderman <pstrawderman@netflix.com>
@kilink kilink force-pushed the type-descriptor-immutable-cache branch from 089e82f to 8485956 Compare May 18, 2026 18:07
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label May 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: waiting-for-triage An issue we've not yet triaged or decided on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants