Skip to content

Ensure that unannotated known class types are singletons#589

Merged
Ladicek merged 1 commit intosmallrye:mainfrom
snazy:special-class-types
Sep 15, 2025
Merged

Ensure that unannotated known class types are singletons#589
Ladicek merged 1 commit intosmallrye:mainfrom
snazy:special-class-types

Conversation

@snazy
Copy link
Contributor

@snazy snazy commented Sep 15, 2025

In particular, this commit prevents "changing" an unbounded wildcard ? to ? extends java.lang.Object. This was caused by a new ClassType instance being created for java.lang.Object, instead of reusing the singleton instance.

@Ladicek
Copy link
Member

Ladicek commented Sep 15, 2025

I've noticed this commit in the previous PR and didn't pay much attention, but I'd like to ask here: what issue does this fix? The PR looks reasonable, but still.

@snazy
Copy link
Contributor Author

snazy commented Sep 15, 2025

I've seen the same ? generic being serialized as a simple ? (annotation-instance referring to ClassType.OBJECT_TYPE, which is then "simplified" as ?) and serialized as ? extends java.lang.Object (annotation instance to a different ClassType for java.lang.Object).

So I went ahead and added the "forceful" indirection via ClassType.create() to ensure that the "proper singletons" are being used everywhere.

@snazy
Copy link
Contributor Author

snazy commented Sep 15, 2025

This seemed much easier than an instance-equals at the call sites.

@Ladicek
Copy link
Member

Ladicek commented Sep 15, 2025

Ah so accidental discovery. OK, I think this makes sense; ? extends java.lang.Object with no annotation on the bound is the same as ?.

@snazy
Copy link
Contributor Author

snazy commented Sep 15, 2025

Or see it as a micro-heap-pressure-optimization ;)

In particular, this commit prevents "changing" an unbounded wildcard `?`
to `? extends java.lang.Object`. This was caused by a new `ClassType`
instance being created for `java.lang.Object`, instead of reusing
the singleton instance.
@Ladicek Ladicek force-pushed the special-class-types branch from c4b3848 to 31acf5a Compare September 15, 2025 11:37
@Ladicek Ladicek changed the title Ensure that unannotated java.lang-special ClassTypes are singletons Ensure that unannotated known class types are singletons Sep 15, 2025
@Ladicek Ladicek merged commit fdd66d8 into smallrye:main Sep 15, 2025
35 checks passed
@snazy snazy deleted the special-class-types branch September 15, 2025 11:46
@Ladicek Ladicek added this to the 3.5.1 milestone Sep 15, 2025
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.

2 participants