3232package com .google .auth .oauth2 ;
3333
3434import java .io .File ;
35+ import java .io .IOException ;
3536
3637/**
3738 * This public class provides shared utilities for common OAuth2 utils or ADC. It also exposes
@@ -45,7 +46,7 @@ public class GoogleAuthUtils {
4546 * @return the path to the well-known Application Default Credentials file location
4647 */
4748 public static final String getWellKnownCredentialsPath () {
48- return getWellKnownCredentialsFile (DefaultCredentialsProvider .DEFAULT ). getAbsolutePath ( );
49+ return getWellKnownCredentialsPath (DefaultCredentialsProvider .DEFAULT );
4950 }
5051
5152 /**
@@ -54,7 +55,11 @@ public static final String getWellKnownCredentialsPath() {
5455 * @return the path to the well-known Application Default Credentials file location
5556 */
5657 static final String getWellKnownCredentialsPath (DefaultCredentialsProvider provider ) {
57- return getWellKnownCredentialsFile (provider ).getAbsolutePath ();
58+ try {
59+ return getWellKnownCredentialsFile (provider ).getAbsolutePath ();
60+ } catch (IOException e ) {
61+ throw new RuntimeException (e );
62+ }
5863 }
5964
6065 /**
@@ -64,13 +69,18 @@ static final String getWellKnownCredentialsPath(DefaultCredentialsProvider provi
6469 * purposes)
6570 * @return the well-known Application Default Credentials file
6671 */
67- static final File getWellKnownCredentialsFile (DefaultCredentialsProvider provider ) {
72+ static final File getWellKnownCredentialsFile (DefaultCredentialsProvider provider )
73+ throws IOException {
6874 File cloudConfigPath ;
6975 String envPath = provider .getEnv ("CLOUDSDK_CONFIG" );
7076 if (envPath != null ) {
7177 cloudConfigPath = new File (envPath );
7278 } else if (provider .getOsName ().indexOf ("windows" ) >= 0 ) {
73- File appDataPath = new File (provider .getEnv ("APPDATA" ));
79+ String appData = provider .getEnv ("APPDATA" );
80+ if (appData == null ) {
81+ throw new IOException (DefaultCredentialsProvider .CLOUDSDK_MISSING_CREDENTIALS );
82+ }
83+ File appDataPath = new File (appData );
7484 cloudConfigPath = new File (appDataPath , provider .CLOUDSDK_CONFIG_DIRECTORY );
7585 } else {
7686 File configPath = new File (provider .getProperty ("user.home" , "" ), ".config" );
0 commit comments