6969import com .google .cloud .storage .UnifiedOpts .ProjectId ;
7070import com .google .cloud .storage .UnifiedOpts .UserProject ;
7171import com .google .common .annotations .VisibleForTesting ;
72+ import com .google .common .base .Suppliers ;
7273import com .google .common .collect .ImmutableList ;
7374import com .google .common .collect .ImmutableSet ;
7475import com .google .common .collect .Streams ;
130131import java .util .concurrent .TimeUnit ;
131132import java .util .function .Consumer ;
132133import java .util .function .Predicate ;
134+ import java .util .function .Supplier ;
133135import java .util .function .UnaryOperator ;
134136import java .util .stream .Stream ;
135137import java .util .stream .StreamSupport ;
@@ -167,7 +169,7 @@ final class GrpcStorageImpl extends BaseService<StorageOptions>
167169
168170 // workaround for https://github.com/googleapis/java-storage/issues/1736
169171 private final Opts <UserProject > defaultOpts ;
170- @ Deprecated private final ProjectId defaultProjectId ;
172+ @ Deprecated private final Supplier < ProjectId > defaultProjectId ;
171173
172174 GrpcStorageImpl (
173175 GrpcStorageOptions options ,
@@ -183,7 +185,7 @@ final class GrpcStorageImpl extends BaseService<StorageOptions>
183185 this .codecs = Conversions .grpc ();
184186 this .retryAlgorithmManager = options .getRetryAlgorithmManager ();
185187 this .syntaxDecoders = new SyntaxDecoders ();
186- this .defaultProjectId = UnifiedOpts .projectId (options .getProjectId ());
188+ this .defaultProjectId = Suppliers . memoize (() -> UnifiedOpts .projectId (options .getProjectId () ));
187189 }
188190
189191 @ Override
@@ -443,6 +445,7 @@ public Page<Bucket> list(BucketListOption... options) {
443445 opts .grpcMetadataMapper ().apply (GrpcCallContext .createDefault ());
444446 ListBucketsRequest request =
445447 defaultProjectId
448+ .get ()
446449 .listBuckets ()
447450 .andThen (opts .listBucketsRequest ())
448451 .apply (ListBucketsRequest .newBuilder ())
0 commit comments