[java] Fix #6239: UseDiamondOperator: Implement heuristic for Super Type Token Pattern#6745
Conversation
|
Compared to main: (comment created at 2026-06-03 20:20:47+00:00 for ee25c14) |
|
And the regression tester kind of proves my point: |
156a6ab to
d988a95
Compare
lukasgraef
left a comment
There was a problem hiding this comment.
Tackling this problem using a heuristic is a great idea!
The implementation also looks clean to me.
One small finding/discussion point from my side: With the current implementation of the heuristic, it seems that two new FNs are introduced in the regression tester report.
Both of which should have flagged the instantiation of reactor.core.publisher.BaseSubscriber:
- https://github.com/spring-projects/spring-framework/blob/v5.3.13/spring-web/src/test/java/org/springframework/http/server/reactive/ChannelSendOperatorTests.java#L173
- https://github.com/spring-projects/spring-framework/blob/v5.3.13/spring-web/src/test/java/org/springframework/http/server/reactive/ChannelSendOperatorTests.java#L143
Maybe we can tighten the heuristic a bit:
- Check whether the class actually has a field of type
java.lang.reflect.Type - Check that the class doesn't implement any interface or extend another class (not really sure about this one, probably the first check is enough)
WDYT?
bf27975 to
916a567
Compare
|
Nice spot, and nice suggestion! I did your #1 - and ChannelSendOperatorTests is gone from the regression report :) |
916a567 to
ee25c14
Compare
Describe the PR
The way I see it, there are two ways to tackle #6239:
The first: create a list of classes which are exempt from the UseDiamondOperator rule. The issue already mentions four of them. This list could be either hard-coded or user-configurable. In either case, someone has to edit the list when another framework creates their one version of the TypeToken. I don't like this.
The second: attempt to find uses of the super type token pattern programmatically. This is what this PR does.
Related issues
Ready?
./mvnw clean verifypasses (checked automatically by github actions)