Skip to content

Commit 3b8d137

Browse files
authored
docs: annotate all Option factory methods with their Nullability bounds (#1775)
Update all option factory methods to explicitly state their Nullability bounds. All methods which take non-primitive parameters are @nonnull, and will be published in the javadocs. Add new tests to explicitly verify null argument validation. All factory methods now check their args for nullness, instead of depending on implicit checking.
1 parent ba49f9d commit 3b8d137

File tree

7 files changed

+300
-100
lines changed

7 files changed

+300
-100
lines changed

google-cloud-storage/src/main/java/com/google/cloud/storage/Blob.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import java.util.Map;
4545
import java.util.Objects;
4646
import java.util.concurrent.TimeUnit;
47+
import org.checkerframework.checker.nullness.qual.NonNull;
4748

4849
/**
4950
* An object in Google Cloud Storage. A {@code Blob} object includes the {@code BlobId} instance,
@@ -128,7 +129,7 @@ public static BlobSourceOption metagenerationNotMatch() {
128129
* blob.
129130
*/
130131
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
131-
public static BlobSourceOption decryptionKey(Key key) {
132+
public static BlobSourceOption decryptionKey(@NonNull Key key) {
132133
return new BlobSourceOption(UnifiedOpts.decryptionKey(key));
133134
}
134135

@@ -139,7 +140,7 @@ public static BlobSourceOption decryptionKey(Key key) {
139140
* @param key the AES256 encoded in base64
140141
*/
141142
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
142-
public static BlobSourceOption decryptionKey(String key) {
143+
public static BlobSourceOption decryptionKey(@NonNull String key) {
143144
return new BlobSourceOption(UnifiedOpts.decryptionKey(key));
144145
}
145146

@@ -148,7 +149,7 @@ public static BlobSourceOption decryptionKey(String key) {
148149
* bucket has requester_pays flag enabled.
149150
*/
150151
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
151-
public static BlobSourceOption userProject(String userProject) {
152+
public static BlobSourceOption userProject(@NonNull String userProject) {
152153
return new BlobSourceOption(UnifiedOpts.userProject(userProject));
153154
}
154155

google-cloud-storage/src/main/java/com/google/cloud/storage/Bucket.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import java.util.List;
4545
import java.util.Map;
4646
import java.util.Objects;
47+
import org.checkerframework.checker.nullness.qual.NonNull;
4748

4849
/**
4950
* A Google cloud storage bucket.
@@ -93,7 +94,7 @@ public static BucketSourceOption metagenerationNotMatch() {
9394
* with 'requester_pays' flag.
9495
*/
9596
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
96-
public static BucketSourceOption userProject(String userProject) {
97+
public static BucketSourceOption userProject(@NonNull String userProject) {
9798
return new BucketSourceOption(UnifiedOpts.userProject(userProject));
9899
}
99100

@@ -142,7 +143,7 @@ private BlobTargetOption(ObjectTargetOpt opt) {
142143

143144
/** Returns an option for specifying blob's predefined ACL configuration. */
144145
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
145-
public static BlobTargetOption predefinedAcl(Storage.PredefinedAcl acl) {
146+
public static BlobTargetOption predefinedAcl(Storage.@NonNull PredefinedAcl acl) {
146147
return new BlobTargetOption(UnifiedOpts.predefinedAcl(acl));
147148
}
148149

@@ -201,7 +202,7 @@ public static BlobTargetOption metagenerationNotMatch(long metageneration) {
201202
* blob.
202203
*/
203204
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
204-
public static BlobTargetOption encryptionKey(Key key) {
205+
public static BlobTargetOption encryptionKey(@NonNull Key key) {
205206
return new BlobTargetOption(UnifiedOpts.encryptionKey(key));
206207
}
207208

@@ -212,7 +213,7 @@ public static BlobTargetOption encryptionKey(Key key) {
212213
* @param key the AES256 encoded in base64
213214
*/
214215
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
215-
public static BlobTargetOption encryptionKey(String key) {
216+
public static BlobTargetOption encryptionKey(@NonNull String key) {
216217
return new BlobTargetOption(UnifiedOpts.encryptionKey(key));
217218
}
218219

@@ -222,7 +223,7 @@ public static BlobTargetOption encryptionKey(String key) {
222223
* @param kmsKeyName the KMS key resource id
223224
*/
224225
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
225-
public static BlobTargetOption kmsKeyName(String kmsKeyName) {
226+
public static BlobTargetOption kmsKeyName(@NonNull String kmsKeyName) {
226227
return new BlobTargetOption(UnifiedOpts.kmsKeyName(kmsKeyName));
227228
}
228229

@@ -231,7 +232,7 @@ public static BlobTargetOption kmsKeyName(String kmsKeyName) {
231232
* with 'requester_pays' flag.
232233
*/
233234
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
234-
public static BlobTargetOption userProject(String userProject) {
235+
public static BlobTargetOption userProject(@NonNull String userProject) {
235236
return new BlobTargetOption(UnifiedOpts.userProject(userProject));
236237
}
237238

@@ -263,7 +264,7 @@ private BlobWriteOption(ObjectTargetOpt opt) {
263264

264265
/** Returns an option for specifying blob's predefined ACL configuration. */
265266
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
266-
public static BlobWriteOption predefinedAcl(Storage.PredefinedAcl acl) {
267+
public static BlobWriteOption predefinedAcl(Storage.@NonNull PredefinedAcl acl) {
267268
return new BlobWriteOption(UnifiedOpts.predefinedAcl(acl));
268269
}
269270

@@ -322,7 +323,7 @@ public static BlobWriteOption metagenerationNotMatch(long metageneration) {
322323
* fail if blobs' data MD5 hash does not match the provided value.
323324
*/
324325
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
325-
public static BlobWriteOption md5Match(String md5) {
326+
public static BlobWriteOption md5Match(@NonNull String md5) {
326327
return new BlobWriteOption(UnifiedOpts.md5Match(md5));
327328
}
328329

@@ -331,7 +332,7 @@ public static BlobWriteOption md5Match(String md5) {
331332
* will fail if blobs' data CRC32C checksum does not match the provided value.
332333
*/
333334
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
334-
public static BlobWriteOption crc32cMatch(String crc32c) {
335+
public static BlobWriteOption crc32cMatch(@NonNull String crc32c) {
335336
return new BlobWriteOption(UnifiedOpts.crc32cMatch(crc32c));
336337
}
337338

@@ -340,7 +341,7 @@ public static BlobWriteOption crc32cMatch(String crc32c) {
340341
* blob.
341342
*/
342343
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
343-
public static BlobWriteOption encryptionKey(Key key) {
344+
public static BlobWriteOption encryptionKey(@NonNull Key key) {
344345
return new BlobWriteOption(UnifiedOpts.encryptionKey(key));
345346
}
346347

@@ -351,7 +352,7 @@ public static BlobWriteOption encryptionKey(Key key) {
351352
* @param key the AES256 encoded in base64
352353
*/
353354
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
354-
public static BlobWriteOption encryptionKey(String key) {
355+
public static BlobWriteOption encryptionKey(@NonNull String key) {
355356
return new BlobWriteOption(UnifiedOpts.encryptionKey(key));
356357
}
357358

@@ -360,7 +361,7 @@ public static BlobWriteOption encryptionKey(String key) {
360361
* with 'requester_pays' flag.
361362
*/
362363
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
363-
public static BlobWriteOption userProject(String userProject) {
364+
public static BlobWriteOption userProject(@NonNull String userProject) {
364365
return new BlobWriteOption(UnifiedOpts.userProject(userProject));
365366
}
366367

google-cloud-storage/src/main/java/com/google/cloud/storage/BucketInfo.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,7 +1061,7 @@ public static DeleteLifecycleAction newDeleteAction() {
10611061
* @param storageClass The new storage class to use when conditions are met for this action.
10621062
*/
10631063
public static SetStorageClassLifecycleAction newSetStorageClassAction(
1064-
StorageClass storageClass) {
1064+
@NonNull StorageClass storageClass) {
10651065
return new SetStorageClassLifecycleAction(storageClass);
10661066
}
10671067

@@ -1080,7 +1080,7 @@ public static LifecycleAction newAbortIncompleteMPUploadAction() {
10801080
* generally not be used, instead use the supported actions, and upgrade the library if necessary
10811081
* to get new supported actions.
10821082
*/
1083-
public static LifecycleAction newLifecycleAction(String actionType) {
1083+
public static LifecycleAction newLifecycleAction(@NonNull String actionType) {
10841084
return new LifecycleAction(actionType);
10851085
}
10861086
}

0 commit comments

Comments
 (0)