@@ -391,9 +391,9 @@ protected static String getAppEngineProjectId() {
391391 if (PlatformInformation .isOnGAEStandard7 ()) {
392392 try {
393393 Class <?> factoryClass =
394- Class .forName ("com.google.appengine.api.appidentity.AppIdentityServiceFactory" );
394+ Class .forName ("com.google.appengine.api.appidentity.AppIdentityServiceFactory" );
395395 Class <?> serviceClass =
396- Class .forName ("com.google.appengine.api.appidentity.AppIdentityService" );
396+ Class .forName ("com.google.appengine.api.appidentity.AppIdentityService" );
397397 Method method = factoryClass .getMethod ("getAppIdentityService" );
398398 Object appIdentityService = method .invoke (null );
399399 method = serviceClass .getMethod ("getServiceAccountName" );
@@ -403,7 +403,8 @@ protected static String getAppEngineProjectId() {
403403 } catch (ClassNotFoundException exception ) {
404404 if (System .getProperty ("com.google.appengine.runtime.version" ) != null ) {
405405 // Could not resolve appengine classes under GAE environment.
406- throw new RuntimeException ("Google App Engine runtime detected "
406+ throw new RuntimeException (
407+ "Google App Engine runtime detected "
407408 + "(the environment variable \" com.google.appengine.runtime.version\" is set), "
408409 + "but unable to resolve appengine-sdk classes. "
409410 + "For more details see "
@@ -419,20 +420,20 @@ protected static String getAppEngineProjectId() {
419420 if (projectId == null ) {
420421 projectId = System .getenv ("GOOGLE_CLOUD_PROJECT" );
421422 }
423+ if (projectId == null ) {
424+ projectId = getAppEngineAppId ();
425+ if (projectId != null && projectId .contains (":" )) {
426+ int colonIndex = projectId .indexOf (":" );
427+ projectId = projectId .substring (colonIndex + 1 );
428+ }
429+ }
422430 if (projectId == null ) {
423431 try {
424432 projectId = getAppEngineProjectIdFromMetadataServer ();
425433 } catch (IOException ignore ) {
426434 projectId = null ;
427435 }
428436 }
429- if (projectId == null ) {
430- projectId = getAppEngineAppId ();
431- if (projectId != null && projectId .contains (":" )) {
432- int colonIndex = projectId .indexOf (":" );
433- projectId = projectId .substring (colonIndex + 1 );
434- }
435- }
436437 return projectId ;
437438 }
438439 }
0 commit comments