Skip to content

Commit e3e9d0b

Browse files
feat(gapic-generator): Add Nullable annotation to generated classes (#13558)
This PR updates the gapic-generator-java to add the JSpecify @nullable annotation to all generated class declarations. This is the second phase in onboarding the generated client libraries to compile-time safety validation, see design doc for more details: [go/sdk:java-jspecify-null-annotations-gapic](http://goto.google.com/sdk:java-jspecify-null-annotations-gapic) Classes Annotated: - Client Classes: AbstractServiceClientClassComposer - Stub Classes: AbstractServiceStubClassComposer and ServiceStubClassComposer - Resource Names: ResourceNameHelperClassComposer Implementation Changes: - Built the parameter variable expression in equals(Object o) as a reference initially, and attached the @nullable annotation during its method argument declaration (with isDecl = true). This prevents IllegalStateException crashes in the generator's strict AST validation engine. - Leveraged a VaporReference type name-hacking trick to render generic type-use annotations (such as List<@nullable ResourceName>) without needing disruptive changes to the core AST reference rendering engine. - Modified two owlbot.py scripts to reflect the signature changes: ‎java-bigquerydatatransfer/owlbot.py & java-bigquerydatatransfer/owlbot.py Verification/Testing: - Please refer to this doc: https://docs.google.com/document/d/1h126pbTGqSwtJyl35E2_vQjM9gNtmWETYCM7PObcvmQ/edit?tab=t.0#heading=h.s4q06jxocx8b --------- Co-authored-by: cloud-java-bot <cloud-java-bot@google.com>
1 parent 537c16c commit e3e9d0b

5,937 files changed

Lines changed: 50032 additions & 37667 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎java-accessapproval/google-cloud-accessapproval/src/main/java/com/google/cloud/accessapproval/v1/AccessApprovalAdminClient.java‎

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import java.util.concurrent.TimeUnit;
3535
import javax.annotation.Generated;
3636
import org.jspecify.annotations.NullMarked;
37+
import org.jspecify.annotations.Nullable;
3738

3839
// AUTO-GENERATED DOCUMENTATION AND CLASS.
3940
/**
@@ -318,7 +319,7 @@
318319
@NullMarked
319320
@Generated("by gapic-generator-java")
320321
public class AccessApprovalAdminClient implements BackgroundResource {
321-
private final AccessApprovalAdminSettings settings;
322+
private final @Nullable AccessApprovalAdminSettings settings;
322323
private final AccessApprovalStub stub;
323324

324325
/** Constructs an instance of AccessApprovalAdminClient with default settings. */
@@ -358,7 +359,7 @@ protected AccessApprovalAdminClient(AccessApprovalStub stub) {
358359
this.stub = stub;
359360
}
360361

361-
public final AccessApprovalAdminSettings getSettings() {
362+
public final @Nullable AccessApprovalAdminSettings getSettings() {
362363
return settings;
363364
}
364365

@@ -392,7 +393,7 @@ public AccessApprovalStub getStub() {
392393
* "organizations/{organization}".
393394
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
394395
*/
395-
public final ListApprovalRequestsPagedResponse listApprovalRequests(FolderName parent) {
396+
public final ListApprovalRequestsPagedResponse listApprovalRequests(@Nullable FolderName parent) {
396397
ListApprovalRequestsMessage request =
397398
ListApprovalRequestsMessage.newBuilder()
398399
.setParent(parent == null ? null : parent.toString())
@@ -426,7 +427,8 @@ public final ListApprovalRequestsPagedResponse listApprovalRequests(FolderName p
426427
* "organizations/{organization}".
427428
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
428429
*/
429-
public final ListApprovalRequestsPagedResponse listApprovalRequests(OrganizationName parent) {
430+
public final ListApprovalRequestsPagedResponse listApprovalRequests(
431+
@Nullable OrganizationName parent) {
430432
ListApprovalRequestsMessage request =
431433
ListApprovalRequestsMessage.newBuilder()
432434
.setParent(parent == null ? null : parent.toString())
@@ -460,7 +462,8 @@ public final ListApprovalRequestsPagedResponse listApprovalRequests(Organization
460462
* "organizations/{organization}".
461463
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
462464
*/
463-
public final ListApprovalRequestsPagedResponse listApprovalRequests(ProjectName parent) {
465+
public final ListApprovalRequestsPagedResponse listApprovalRequests(
466+
@Nullable ProjectName parent) {
464467
ListApprovalRequestsMessage request =
465468
ListApprovalRequestsMessage.newBuilder()
466469
.setParent(parent == null ? null : parent.toString())
@@ -636,7 +639,7 @@ public final ListApprovalRequestsPagedResponse listApprovalRequests(
636639
* "{projects|folders|organizations}/{id}/approvalRequests/{approval_request}"
637640
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
638641
*/
639-
public final ApprovalRequest getApprovalRequest(ApprovalRequestName name) {
642+
public final ApprovalRequest getApprovalRequest(@Nullable ApprovalRequestName name) {
640643
GetApprovalRequestMessage request =
641644
GetApprovalRequestMessage.newBuilder()
642645
.setName(name == null ? null : name.toString())
@@ -980,7 +983,8 @@ public final ApprovalRequest invalidateApprovalRequest(InvalidateApprovalRequest
980983
* "{projects|folders|organizations}/{id}/accessApprovalSettings"
981984
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
982985
*/
983-
public final AccessApprovalSettings getAccessApprovalSettings(AccessApprovalSettingsName name) {
986+
public final AccessApprovalSettings getAccessApprovalSettings(
987+
@Nullable AccessApprovalSettingsName name) {
984988
GetAccessApprovalSettingsMessage request =
985989
GetAccessApprovalSettingsMessage.newBuilder()
986990
.setName(name == null ? null : name.toString())
@@ -1204,7 +1208,7 @@ public final AccessApprovalSettings updateAccessApprovalSettings(
12041208
* @param name Name of the AccessApprovalSettings to delete.
12051209
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
12061210
*/
1207-
public final void deleteAccessApprovalSettings(AccessApprovalSettingsName name) {
1211+
public final void deleteAccessApprovalSettings(@Nullable AccessApprovalSettingsName name) {
12081212
DeleteAccessApprovalSettingsMessage request =
12091213
DeleteAccessApprovalSettingsMessage.newBuilder()
12101214
.setName(name == null ? null : name.toString())
@@ -1457,9 +1461,10 @@ public static class ListApprovalRequestsPage
14571461
ListApprovalRequestsPage> {
14581462

14591463
private ListApprovalRequestsPage(
1460-
PageContext<ListApprovalRequestsMessage, ListApprovalRequestsResponse, ApprovalRequest>
1464+
@Nullable
1465+
PageContext<ListApprovalRequestsMessage, ListApprovalRequestsResponse, ApprovalRequest>
14611466
context,
1462-
ListApprovalRequestsResponse response) {
1467+
@Nullable ListApprovalRequestsResponse response) {
14631468
super(context, response);
14641469
}
14651470

@@ -1469,15 +1474,17 @@ private static ListApprovalRequestsPage createEmptyPage() {
14691474

14701475
@Override
14711476
protected ListApprovalRequestsPage createPage(
1472-
PageContext<ListApprovalRequestsMessage, ListApprovalRequestsResponse, ApprovalRequest>
1477+
@Nullable
1478+
PageContext<ListApprovalRequestsMessage, ListApprovalRequestsResponse, ApprovalRequest>
14731479
context,
1474-
ListApprovalRequestsResponse response) {
1480+
@Nullable ListApprovalRequestsResponse response) {
14751481
return new ListApprovalRequestsPage(context, response);
14761482
}
14771483

14781484
@Override
14791485
public ApiFuture<ListApprovalRequestsPage> createPageAsync(
1480-
PageContext<ListApprovalRequestsMessage, ListApprovalRequestsResponse, ApprovalRequest>
1486+
@Nullable
1487+
PageContext<ListApprovalRequestsMessage, ListApprovalRequestsResponse, ApprovalRequest>
14811488
context,
14821489
ApiFuture<ListApprovalRequestsResponse> futureResponse) {
14831490
return super.createPageAsync(context, futureResponse);
@@ -1493,7 +1500,7 @@ public static class ListApprovalRequestsFixedSizeCollection
14931500
ListApprovalRequestsFixedSizeCollection> {
14941501

14951502
private ListApprovalRequestsFixedSizeCollection(
1496-
List<ListApprovalRequestsPage> pages, int collectionSize) {
1503+
@Nullable List<ListApprovalRequestsPage> pages, int collectionSize) {
14971504
super(pages, collectionSize);
14981505
}
14991506

@@ -1503,7 +1510,7 @@ private static ListApprovalRequestsFixedSizeCollection createEmptyCollection() {
15031510

15041511
@Override
15051512
protected ListApprovalRequestsFixedSizeCollection createCollection(
1506-
List<ListApprovalRequestsPage> pages, int collectionSize) {
1513+
@Nullable List<ListApprovalRequestsPage> pages, int collectionSize) {
15071514
return new ListApprovalRequestsFixedSizeCollection(pages, collectionSize);
15081515
}
15091516
}

‎java-accessapproval/google-cloud-accessapproval/src/main/java/com/google/cloud/accessapproval/v1/AccessApprovalAdminSettings.java‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import java.util.List;
3737
import javax.annotation.Generated;
3838
import org.jspecify.annotations.NullMarked;
39+
import org.jspecify.annotations.Nullable;
3940

4041
// AUTO-GENERATED DOCUMENTATION AND CLASS.
4142
/**
@@ -207,7 +208,7 @@ public static Builder newHttpJsonBuilder() {
207208
}
208209

209210
/** Returns a new builder for this class. */
210-
public static Builder newBuilder(ClientContext clientContext) {
211+
public static Builder newBuilder(@Nullable ClientContext clientContext) {
211212
return new Builder(clientContext);
212213
}
213214

@@ -227,7 +228,7 @@ protected Builder() throws IOException {
227228
this(((ClientContext) null));
228229
}
229230

230-
protected Builder(ClientContext clientContext) {
231+
protected Builder(@Nullable ClientContext clientContext) {
231232
super(AccessApprovalStubSettings.newBuilder(clientContext));
232233
}
233234

‎java-accessapproval/google-cloud-accessapproval/src/main/java/com/google/cloud/accessapproval/v1/stub/AccessApprovalStubSettings.java‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
import java.util.List;
6969
import javax.annotation.Generated;
7070
import org.jspecify.annotations.NullMarked;
71+
import org.jspecify.annotations.Nullable;
7172

7273
// AUTO-GENERATED DOCUMENTATION AND CLASS.
7374
/**
@@ -371,7 +372,7 @@ public static Builder newHttpJsonBuilder() {
371372
}
372373

373374
/** Returns a new builder for this class. */
374-
public static Builder newBuilder(ClientContext clientContext) {
375+
public static Builder newBuilder(@Nullable ClientContext clientContext) {
375376
return new Builder(clientContext);
376377
}
377378

@@ -481,7 +482,7 @@ protected Builder() {
481482
this(((ClientContext) null));
482483
}
483484

484-
protected Builder(ClientContext clientContext) {
485+
protected Builder(@Nullable ClientContext clientContext) {
485486
super(clientContext);
486487

487488
listApprovalRequestsSettings =

‎java-accessapproval/proto-google-cloud-accessapproval-v1/src/main/java/com/google/cloud/accessapproval/v1/AccessApprovalSettingsName.java‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.util.Objects;
2828
import javax.annotation.Generated;
2929
import org.jspecify.annotations.NullMarked;
30+
import org.jspecify.annotations.Nullable;
3031

3132
// AUTO-GENERATED DOCUMENTATION AND CLASS.
3233
@NullMarked
@@ -137,7 +138,7 @@ public static String formatOrganizationName(String organization) {
137138
return newOrganizationBuilder().setOrganization(organization).build().toString();
138139
}
139140

140-
public static AccessApprovalSettingsName parse(String formattedString) {
141+
public static @Nullable AccessApprovalSettingsName parse(String formattedString) {
141142
if (formattedString.isEmpty()) {
142143
return null;
143144
}
@@ -163,7 +164,7 @@ public static List<AccessApprovalSettingsName> parseList(List<String> formattedS
163164
return list;
164165
}
165166

166-
public static List<String> toStringList(List<AccessApprovalSettingsName> values) {
167+
public static List<String> toStringList(List<@Nullable AccessApprovalSettingsName> values) {
167168
List<String> list = new ArrayList<>(values.size());
168169
for (AccessApprovalSettingsName value : values) {
169170
if (value == null) {
@@ -213,7 +214,7 @@ public String toString() {
213214
}
214215

215216
@Override
216-
public boolean equals(Object o) {
217+
public boolean equals(@Nullable Object o) {
217218
if (o == this) {
218219
return true;
219220
}

‎java-accessapproval/proto-google-cloud-accessapproval-v1/src/main/java/com/google/cloud/accessapproval/v1/ApprovalRequestName.java‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.util.Objects;
2828
import javax.annotation.Generated;
2929
import org.jspecify.annotations.NullMarked;
30+
import org.jspecify.annotations.Nullable;
3031

3132
// AUTO-GENERATED DOCUMENTATION AND CLASS.
3233
@NullMarked
@@ -166,7 +167,7 @@ public static String formatOrganizationApprovalRequestName(
166167
.toString();
167168
}
168169

169-
public static ApprovalRequestName parse(String formattedString) {
170+
public static @Nullable ApprovalRequestName parse(String formattedString) {
170171
if (formattedString.isEmpty()) {
171172
return null;
172173
}
@@ -193,7 +194,7 @@ public static List<ApprovalRequestName> parseList(List<String> formattedStrings)
193194
return list;
194195
}
195196

196-
public static List<String> toStringList(List<ApprovalRequestName> values) {
197+
public static List<String> toStringList(List<@Nullable ApprovalRequestName> values) {
197198
List<String> list = new ArrayList<>(values.size());
198199
for (ApprovalRequestName value : values) {
199200
if (value == null) {
@@ -246,7 +247,7 @@ public String toString() {
246247
}
247248

248249
@Override
249-
public boolean equals(Object o) {
250+
public boolean equals(@Nullable Object o) {
250251
if (o == this) {
251252
return true;
252253
}

‎java-accessapproval/proto-google-cloud-accessapproval-v1/src/main/java/com/google/cloud/accessapproval/v1/FolderName.java‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.Objects;
2727
import javax.annotation.Generated;
2828
import org.jspecify.annotations.NullMarked;
29+
import org.jspecify.annotations.Nullable;
2930

3031
// AUTO-GENERATED DOCUMENTATION AND CLASS.
3132
@NullMarked
@@ -65,7 +66,7 @@ public static String format(String folder) {
6566
return newBuilder().setFolder(folder).build().toString();
6667
}
6768

68-
public static FolderName parse(String formattedString) {
69+
public static @Nullable FolderName parse(String formattedString) {
6970
if (formattedString.isEmpty()) {
7071
return null;
7172
}
@@ -83,7 +84,7 @@ public static List<FolderName> parseList(List<String> formattedStrings) {
8384
return list;
8485
}
8586

86-
public static List<String> toStringList(List<FolderName> values) {
87+
public static List<String> toStringList(List<@Nullable FolderName> values) {
8788
List<String> list = new ArrayList<>(values.size());
8889
for (FolderName value : values) {
8990
if (value == null) {
@@ -125,7 +126,7 @@ public String toString() {
125126
}
126127

127128
@Override
128-
public boolean equals(Object o) {
129+
public boolean equals(@Nullable Object o) {
129130
if (o == this) {
130131
return true;
131132
}

‎java-accessapproval/proto-google-cloud-accessapproval-v1/src/main/java/com/google/cloud/accessapproval/v1/OrganizationName.java‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.Objects;
2727
import javax.annotation.Generated;
2828
import org.jspecify.annotations.NullMarked;
29+
import org.jspecify.annotations.Nullable;
2930

3031
// AUTO-GENERATED DOCUMENTATION AND CLASS.
3132
@NullMarked
@@ -65,7 +66,7 @@ public static String format(String organization) {
6566
return newBuilder().setOrganization(organization).build().toString();
6667
}
6768

68-
public static OrganizationName parse(String formattedString) {
69+
public static @Nullable OrganizationName parse(String formattedString) {
6970
if (formattedString.isEmpty()) {
7071
return null;
7172
}
@@ -83,7 +84,7 @@ public static List<OrganizationName> parseList(List<String> formattedStrings) {
8384
return list;
8485
}
8586

86-
public static List<String> toStringList(List<OrganizationName> values) {
87+
public static List<String> toStringList(List<@Nullable OrganizationName> values) {
8788
List<String> list = new ArrayList<>(values.size());
8889
for (OrganizationName value : values) {
8990
if (value == null) {
@@ -125,7 +126,7 @@ public String toString() {
125126
}
126127

127128
@Override
128-
public boolean equals(Object o) {
129+
public boolean equals(@Nullable Object o) {
129130
if (o == this) {
130131
return true;
131132
}

‎java-accessapproval/proto-google-cloud-accessapproval-v1/src/main/java/com/google/cloud/accessapproval/v1/ProjectName.java‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.Objects;
2727
import javax.annotation.Generated;
2828
import org.jspecify.annotations.NullMarked;
29+
import org.jspecify.annotations.Nullable;
2930

3031
// AUTO-GENERATED DOCUMENTATION AND CLASS.
3132
@NullMarked
@@ -65,7 +66,7 @@ public static String format(String project) {
6566
return newBuilder().setProject(project).build().toString();
6667
}
6768

68-
public static ProjectName parse(String formattedString) {
69+
public static @Nullable ProjectName parse(String formattedString) {
6970
if (formattedString.isEmpty()) {
7071
return null;
7172
}
@@ -83,7 +84,7 @@ public static List<ProjectName> parseList(List<String> formattedStrings) {
8384
return list;
8485
}
8586

86-
public static List<String> toStringList(List<ProjectName> values) {
87+
public static List<String> toStringList(List<@Nullable ProjectName> values) {
8788
List<String> list = new ArrayList<>(values.size());
8889
for (ProjectName value : values) {
8990
if (value == null) {
@@ -125,7 +126,7 @@ public String toString() {
125126
}
126127

127128
@Override
128-
public boolean equals(Object o) {
129+
public boolean equals(@Nullable Object o) {
129130
if (o == this) {
130131
return true;
131132
}

0 commit comments

Comments
 (0)