@@ -312,8 +312,9 @@ protected ServiceOptions(Class<? extends ServiceFactory<ServiceT, OptionsT>> ser
312312 httpTransportFactory = firstNonNull (builder .httpTransportFactory ,
313313 getFromServiceLoader (HttpTransportFactory .class , DefaultHttpTransportFactory .INSTANCE ));
314314 httpTransportFactoryClassName = httpTransportFactory .getClass ().getName ();
315- authCredentials = firstNonNull (builder .authCredentials , defaultAuthCredentials ());
316- authCredentialsState = authCredentials .capture ();
315+ authCredentials =
316+ builder .authCredentials != null ? builder .authCredentials : defaultAuthCredentials ();
317+ authCredentialsState = authCredentials != null ? authCredentials .capture () : null ;
317318 retryParams = builder .retryParams ;
318319 serviceFactory = firstNonNull (builder .serviceFactory ,
319320 getFromServiceLoader (serviceFactoryClass , defaultServiceFactory ()));
@@ -349,7 +350,7 @@ private static AuthCredentials defaultAuthCredentials() {
349350 try {
350351 return AuthCredentials .createApplicationDefaults ();
351352 } catch (Exception ex ) {
352- return AuthCredentials . noCredentials () ;
353+ return null ;
353354 }
354355 }
355356
@@ -509,12 +510,15 @@ public RetryParams retryParams() {
509510 * options.
510511 */
511512 public HttpRequestInitializer httpRequestInitializer () {
512- final HttpRequestInitializer baseRequestInitializer =
513- new HttpCredentialsAdapter (authCredentials ().credentials ().createScoped (scopes ()));
513+ final HttpRequestInitializer delegate = authCredentials () != null
514+ ? new HttpCredentialsAdapter (authCredentials ().credentials ().createScoped (scopes ()))
515+ : null ;
514516 return new HttpRequestInitializer () {
515517 @ Override
516518 public void initialize (HttpRequest httpRequest ) throws IOException {
517- baseRequestInitializer .initialize (httpRequest );
519+ if (delegate != null ) {
520+ delegate .initialize (httpRequest );
521+ }
518522 if (connectTimeout >= 0 ) {
519523 httpRequest .setConnectTimeout (connectTimeout );
520524 }
@@ -580,7 +584,7 @@ private void readObject(ObjectInputStream input) throws IOException, ClassNotFou
580584 httpTransportFactory = newInstance (httpTransportFactoryClassName );
581585 serviceFactory = newInstance (serviceFactoryClassName );
582586 serviceRpcFactory = newInstance (serviceRpcFactoryClassName );
583- authCredentials = authCredentialsState .restore ();
587+ authCredentials = authCredentialsState != null ? authCredentialsState .restore () : null ;
584588 }
585589
586590 private static <T > T newInstance (String className ) throws IOException , ClassNotFoundException {
0 commit comments