Skip to content

feat(generator): wire transport stub delegation to resumable upload stubs - #14304

Merged
whowes merged 1 commit into
whowes/showcase-baseline-resumable-uploadfrom
whowes/generator-transport-stub-delegation
Sep 9, 2026
Merged

whowes merged 1 commit into
whowes/showcase-baseline-resumable-uploadfrom
whowes/generator-transport-stub-delegation

Conversation

@whowes

@whowes whowes commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Work in progress, not ready for review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for resumable uploads in the GAPIC generator for Java by adding delegation to HttpJsonServiceResumableUploadStub in both gRPC and HTTP/REST transport stub composers, along with corresponding unit tests. The review feedback focuses on refactoring opportunities to simplify the generated code and method signatures. Specifically, the reviewer suggests removing the unused typeStore parameter from createResumableUploadCallableGetterMethods and passing the resolved resumableUploadStubVarExpr directly to createStubOverrideMethods and the close() method generation to avoid redundant variable recreation and condition checks.

Comment on lines 263 to +264
createStubOverrideMethods(
classMemberVarExprs.get(BACKGROUND_RESOURCES_MEMBER_NAME), service));
classMemberVarExprs.get(BACKGROUND_RESOURCES_MEMBER_NAME), service, typeStore));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Simplify the call to createStubOverrideMethods by passing the already resolved resumableUploadStubVarExpr from classMemberVarExprs instead of typeStore. This avoids recreating the variable expression and re-evaluating the resumable upload condition inside the method.

Suggested change
createStubOverrideMethods(
classMemberVarExprs.get(BACKGROUND_RESOURCES_MEMBER_NAME), service));
classMemberVarExprs.get(BACKGROUND_RESOURCES_MEMBER_NAME), service, typeStore));
createStubOverrideMethods(
classMemberVarExprs.get(BACKGROUND_RESOURCES_MEMBER_NAME),
service,
classMemberVarExprs.get(RESUMABLE_UPLOAD_STUB_MEMBER_NAME)));

javaMethods.addAll(createCallableGetterMethods(callableClassMemberVarExprs));
if (service.methods().stream().anyMatch(Method::isResumableUpload)) {
javaMethods.addAll(
createResumableUploadCallableGetterMethods(service, typeStore, classMemberVarExprs));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Remove the unused typeStore parameter from the call to createResumableUploadCallableGetterMethods.

Suggested change
createResumableUploadCallableGetterMethods(service, typeStore, classMemberVarExprs));
createResumableUploadCallableGetterMethods(service, classMemberVarExprs));

Comment on lines +1171 to +1172
protected List<MethodDefinition> createResumableUploadCallableGetterMethods(
Service service, TypeStore typeStore, Map<String, VariableExpr> classMemberVarExprs) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Remove the unused TypeStore typeStore parameter from the createResumableUploadCallableGetterMethods method signature.

Suggested change
protected List<MethodDefinition> createResumableUploadCallableGetterMethods(
Service service, TypeStore typeStore, Map<String, VariableExpr> classMemberVarExprs) {
protected List<MethodDefinition> createResumableUploadCallableGetterMethods(
Service service, Map<String, VariableExpr> classMemberVarExprs) {

Comment on lines 1200 to +1201
private List<MethodDefinition> createStubOverrideMethods(
VariableExpr backgroundResourcesVarExpr, Service service) {
VariableExpr backgroundResourcesVarExpr, Service service, TypeStore typeStore) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Update the signature of createStubOverrideMethods to accept the resumableUploadStubVarExpr directly instead of TypeStore typeStore.

Suggested change
private List<MethodDefinition> createStubOverrideMethods(
VariableExpr backgroundResourcesVarExpr, Service service) {
VariableExpr backgroundResourcesVarExpr, Service service, TypeStore typeStore) {
private List<MethodDefinition> createStubOverrideMethods(
VariableExpr backgroundResourcesVarExpr,
Service service,
VariableExpr resumableUploadStubVarExpr) {

Comment on lines +1279 to +1304
if (service.methods().stream().anyMatch(Method::isResumableUpload)) {
VariableExpr resumableUploadStubVarExpr =
VariableExpr.withVariable(
Variable.builder()
.setName(RESUMABLE_UPLOAD_STUB_MEMBER_NAME)
.setType(
typeStore.get(String.format("HttpJson%sResumableUploadStub", service.name())))
.build());
Statement closeResumableUploadStubStmt =
ExprStatement.withExpr(
MethodInvocationExpr.builder()
.setExprReferenceExpr(resumableUploadStubVarExpr)
.setMethodName("close")
.build());
if (isResumableUploadStubNullable()) {
tryBodyStatements.add(
IfStatement.builder()
.setConditionExpr(
RelationalOperationExpr.notEqualToWithExprs(
resumableUploadStubVarExpr, ValueExpr.createNullExpr()))
.setBody(Arrays.asList(closeResumableUploadStubStmt))
.build());
} else {
tryBodyStatements.add(closeResumableUploadStubStmt);
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Simplify the close() method generation by using the passed resumableUploadStubVarExpr directly and checking if it is non-null, rather than re-evaluating the service methods and recreating the variable expression.

    if (resumableUploadStubVarExpr != null) {
      Statement closeResumableUploadStubStmt =
          ExprStatement.withExpr(
              MethodInvocationExpr.builder()
                  .setExprReferenceExpr(resumableUploadStubVarExpr)
                  .setMethodName("close")
                  .build());
      if (isResumableUploadStubNullable()) {
        tryBodyStatements.add(
            IfStatement.builder()
                .setConditionExpr(
                    RelationalOperationExpr.notEqualToWithExprs(
                        resumableUploadStubVarExpr, ValueExpr.createNullExpr()))
                .setBody(Arrays.asList(closeResumableUploadStubStmt))
                .build());
      } else {
        tryBodyStatements.add(closeResumableUploadStubStmt);
      }
    }
References
  1. When using lazily initialized resources (such as ExecutorService), ensure that teardown or close methods perform explicit null checks before invoking methods on them to prevent NullPointerException.

Comment on lines +363 to +364
protected List<MethodDefinition> createResumableUploadCallableGetterMethods(
Service service, TypeStore typeStore, Map<String, VariableExpr> classMemberVarExprs) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Remove the unused TypeStore typeStore parameter from the overridden createResumableUploadCallableGetterMethods method signature to match the base class.

Suggested change
protected List<MethodDefinition> createResumableUploadCallableGetterMethods(
Service service, TypeStore typeStore, Map<String, VariableExpr> classMemberVarExprs) {
@Override
protected List<MethodDefinition> createResumableUploadCallableGetterMethods(
Service service, Map<String, VariableExpr> classMemberVarExprs) {

@whowes
whowes added this pull request to stack #14308 September 9, 2026 00:10
@whowes
whowes removed this pull request from stack #14308 September 9, 2026 02:59
@whowes
whowes force-pushed the whowes/generator-resumable-upload-stub-composer branch from 8cb5081 to e8fec50 Compare September 9, 2026 03:47
@whowes
whowes force-pushed the whowes/generator-transport-stub-delegation branch from 1169a63 to daf1b64 Compare September 9, 2026 03:47
Base automatically changed from whowes/generator-resumable-upload-stub-composer to whowes/showcase-baseline-resumable-upload September 9, 2026 03:47
@whowes
whowes merged commit daf1b64 into whowes/showcase-baseline-resumable-upload Sep 9, 2026
71 of 73 checks passed
@whowes
whowes deleted the whowes/generator-transport-stub-delegation branch September 9, 2026 03:47
@whowes
whowes restored the whowes/generator-transport-stub-delegation branch September 9, 2026 03:56
@sonarqubecloud

sonarqubecloud Bot commented Sep 9, 2026

Copy link
Copy Markdown

@sonarqubecloud

sonarqubecloud Bot commented Sep 9, 2026

Copy link
Copy Markdown

❌ The last analysis has failed.

See analysis details on SonarQube Cloud

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.

1 participant