Source:
void updateCachedItemWithResult(final String resource, final String clientId, final AuthenticationResult result, final TokenCacheItem cachedItem) throws AuthenticationException { final String methodName = ":updateCachedItemWithResult"; if (result == null) { Logger.v(TAG + methodName, "AuthenticationResult is null, cannot update cache."); throw new IllegalArgumentException("result"); } if (!StringExtensions.isNullOrBlank(result.getAuthority())) { mAuthority = result.getAuthority(); } if (result.getStatus() == AuthenticationStatus.Succeeded) { Logger.v(TAG + methodName, "Save returned AuthenticationResult into cache."); if (cachedItem != null && cachedItem.getUserInfo() != null && result.getUserInfo() == null) { result.setUserInfo(cachedItem.getUserInfo()); result.setIdToken(cachedItem.getRawIdToken()); result.setTenantId(cachedItem.getTenantId()); } try { if (mUseCommonCache && !UrlExtensions.isADFSAuthority(new URL(mAuthority))) { updateTokenCacheUsingCommonCache(resource, clientId, result); } else { updateTokenCache(resource, clientId, result); } } catch (MalformedURLException e) { throw new AuthenticationException(ADALError.DEVELOPER_AUTHORITY_IS_NOT_VALID_URL, e.getMessage(), e); } } else if (AuthenticationConstants.OAuth2ErrorCode.INVALID_GRANT.equalsIgnoreCase(result.getErrorCode())) { try { mAuthority = getAuthorityUrlWithPreferredCache(); }catch (MalformedURLException e){ Logger.d(TAG + methodName, "Authority from preferred caches is invalid"); } Logger.v(TAG + methodName, "Received INVALID_GRANT error code, remove existing cache entry."); removeTokenCacheItem(cachedItem, resource); } }

Target:
void updateCachedItemWithResult(final String resource, final String clientId, final AuthenticationResult result, final TokenCacheItem cachedItem) throws AuthenticationException { final String methodName = ":updateCachedItemWithResult"; if (result == null) { Logger.v(TAG + methodName, "AuthenticationResult is null, cannot update cache."); throw new IllegalArgumentException("result"); } if (!StringExtensions.isNullOrBlank(result.getAuthority())) { mAuthority = result.getAuthority(); } if (result.getStatus() == AuthenticationStatus.Succeeded) { Logger.v(TAG + methodName, "Save returned AuthenticationResult into cache."); if (cachedItem != null && cachedItem.getUserInfo() != null && result.getUserInfo() == null) { result.setUserInfo(cachedItem.getUserInfo()); result.setIdToken(cachedItem.getRawIdToken()); result.setTenantId(cachedItem.getTenantId()); } try { if (mUseCommonCache && !UrlExtensions.isADFSAuthority(new URL(mAuthority))) { updateTokenCacheUsingCommonCache(resource, clientId, result); } else { updateTokenCache(resource, clientId, result); } } catch (MalformedURLException e) { throw new AuthenticationException(ADALError.DEVELOPER_AUTHORITY_IS_NOT_VALID_URL, e.getMessage(), e); } } else if (AuthenticationConstants.OAuth2ErrorCode.INVALID_GRANT.equalsIgnoreCase(result.getErrorCode())) { try { mAuthority = getAuthorityUrlWithPreferredCache(); } catch (final MalformedURLException e) { com.microsoft.identity.common.internal.logging.Logger.error(TAG, "Authority from preferred cache is invalid", null); com.microsoft.identity.common.internal.logging.Logger.errorPII(TAG, "Failed with Exception", e); } Logger.v(TAG + methodName, "Received INVALID_GRANT error code, remove existing cache entry."); removeTokenCacheItem(cachedItem, resource); } }