Skip to content

Commit 6c40825

Browse files
author
Ajay Kannan
committed
Make projectIdRequired() method protected. Also supply nice error message if project could not be determined and is required
1 parent ad12f41 commit 6c40825

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

gcloud-java-core/src/main/java/com/google/gcloud/ServiceOptions.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package com.google.gcloud;
1818

1919
import static com.google.common.base.MoreObjects.firstNonNull;
20-
import static com.google.common.base.Preconditions.checkNotNull;
20+
import static com.google.common.base.Preconditions.checkArgument;
2121
import static java.nio.charset.StandardCharsets.UTF_8;
2222

2323
import com.google.api.client.extensions.appengine.http.UrlFetchTransport;
@@ -308,7 +308,10 @@ protected ServiceOptions(Class<? extends ServiceFactory<ServiceT, OptionsT>> ser
308308
Builder<ServiceT, ServiceRpcT, OptionsT, ?> builder) {
309309
projectId = builder.projectId != null ? builder.projectId : defaultProject();
310310
if (projectIdRequired()) {
311-
checkNotNull(projectId);
311+
checkArgument(
312+
projectId != null,
313+
"A project ID is required for this service but could not be determined from the builder or "
314+
+ "the environment. Please set a project ID using the builder.");
312315
}
313316
host = firstNonNull(builder.host, defaultHost());
314317
httpTransportFactory = firstNonNull(builder.httpTransportFactory,
@@ -334,7 +337,7 @@ protected ServiceOptions(Class<? extends ServiceFactory<ServiceT, OptionsT>> ser
334337
*
335338
* @return true if a project ID is required to use the service, false if not.
336339
*/
337-
public boolean projectIdRequired() {
340+
protected boolean projectIdRequired() {
338341
return true;
339342
}
340343

0 commit comments

Comments
 (0)