gax-java
gax-java copied to clipboard
fix: change return types of build/toBuilder methods to not cause unchecked cast warnings
SonarCloud Quality Gate failed. 
0 Bugs
0 Vulnerabilities
0 Security Hotspots
2 Code Smells
No Coverage information
0.0% Duplication
@dpcollins-google Can you please provide some more context for this change? Is there a related issue somewhere? Thanks!
Sure. When building google-cloud-pubsublite, I get a lot of warnings like this with generated code:
[WARNING] /Users/dpcollins/Documents/java-pubsublite/google-cloud-pubsublite/src/main/java/com/google/cloud/pubsublite/v1/PublisherServiceSettings.java:[127,17] [unchecked] toBuilder() in PublisherServiceSettings overrides <B>toBuilder() in ClientSettings
return type requires unchecked conversion from com.google.cloud.pubsublite.v1.PublisherServiceSettings.Builder to B
where B,SettingsT are type-variables:
B extends com.google.api.gax.rpc.ClientSettings.Builder<SettingsT,B> declared in method <B>toBuilder()
SettingsT extends ClientSettings<SettingsT> declared in class ClientSettings
This is because the toBuilder abstract method claims to be generic- but is actually only instantiated for one builder type, while the base class method claims it should be instantiated in derived types for all instances of ClientSettings.Builder in every implementation. Since it's okay to override the return type of an abstract method in java as long as the new return type conforms to the abstract one, this change will not cause failing builds since all builders already must conform to Builder<SettingsT, ?>
I also see errors like this:
[WARNING] /Users/dpcollins/Documents/java-pubsublite/google-cloud-pubsublite/src/main/java/com/google/cloud/pubsublite/v1/stub/CursorServiceStubSettings.java:[421,37] [unchecked] build() in com.google.cloud.pubsublite.v1.stub.CursorServiceStubSettings.Builder overrides <B>build() in com.google.api.gax.rpc.StubSettings.Builder
return type requires unchecked conversion from CursorServiceStubSettings to StubSettings<B>
where B is a type-variable:
B extends StubSettings<B> declared in method <B>build()
Which is due to the same issue with the build() method, although for this one we already have access to the settings object type as a generic type parameter.
@dpcollins-google Is current gax causing errors or warnings for you? If it is just warnings, given that those classes are used literally everywhere in whole google cloud and Ads libraries (I'm worrying especially about Ads ones, because they have custom post-processing and manual layer), I would propose to refrain from pushing this changes.
This would also fix this issue: https://github.com/googleapis/gapic-generator-java/issues/1306
The repository has moved to https://github.com/googleapis/sdk-platform-java/tree/main/gax-java. We had triaged pull requests and had moved necessary ones to the new locations. Closing this pull request.