gax-java icon indicating copy to clipboard operation
gax-java copied to clipboard

Consider removing abstract toBuilder

Open igorbernstein2 opened this issue 7 years ago • 7 comments

Gax uses a pattern of abstract <B extends Builder<SettingsT, B>> B toBuilder(); in a base class, expecting a subclass to override it with a concrete return type.

This causes warnings like:

BigtableTableAdminStubSettings.java:[764,43] build() in com.google.cloud.bigtable.admin.v2.stub.BigtableTableAdminStubSettings.Builder overrides <B>build() in com.google.api.gax.rpc.StubSettings.Builder
  return type requires unchecked conversion from com.google.cloud.bigtable.admin.v2.stub.BigtableTableAdminStubSettings to com.google.api.gax.rpc.StubSettings<B>

It might be cleaner remove the abstract toBuilder() method from the base classes and trust that the subclasses will implement that method

igorbernstein2 avatar Feb 03 '18 05:02 igorbernstein2

@garrettjonesgoogle can you take a look at this?

igorbernstein2 avatar Feb 17 '18 16:02 igorbernstein2

It seems like it should be possible to fix the parameterization to get this to work...

garrettjonesgoogle avatar Feb 19 '18 05:02 garrettjonesgoogle

I don't think this is possible. The base class's toBuilder return type would have to include a self referential parameter that includes its builder class, which will be an inner class that hasn't been defined yet.

igorbernstein2 avatar Feb 20 '18 15:02 igorbernstein2

This is likely an API breaking change and a major version update. Is it worth that?

elharo avatar Dec 13 '19 12:12 elharo

I don’t think it’s worth doing a major version bump for this, but I would argue that if a major version were to happen, this should be included. Maybe this can be included in a v2 hotlist? (Along with making ClientContext internal)

igorbernstein2 avatar Dec 13 '19 15:12 igorbernstein2

We missed the opportunity for v2 — is this still worth doing at the next breaking change?

meredithslota avatar Feb 18 '22 01:02 meredithslota

I'm not sure when we'll have the next major version bump, but yes, it would have to be filed under that.

meltsufin avatar Feb 28 '22 18:02 meltsufin