Fixes #426: Crash fix caused by NPE

This commit is contained in:
maskara 2017-03-12 14:18:41 +05:30
parent 46f081d652
commit 6cecaf9e8c
2 changed files with 10 additions and 3 deletions

View file

@ -312,4 +312,8 @@ public class Utils {
} }
return title; return title;
} }
public static boolean isNullOrWhiteSpace(String value) {
return value == null || value.trim().isEmpty();
}
} }

View file

@ -49,13 +49,16 @@ public class ModificationsSyncAdapter extends AbstractThreadedSyncAdapter {
String authCookie; String authCookie;
try { try {
authCookie = AccountManager.get(getContext()).blockingGetAuthToken(account, "", false); authCookie = AccountManager.get(getContext()).blockingGetAuthToken(account, "", false);
} catch (OperationCanceledException e) { } catch (OperationCanceledException | AuthenticatorException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} catch (IOException e) { } catch (IOException e) {
Log.d("Commons", "Could not authenticate :("); Log.d("Commons", "Could not authenticate :(");
return; return;
} catch (AuthenticatorException e) { }
throw new RuntimeException(e);
if(Utils.isNullOrWhiteSpace(authCookie)) {
Log.d("Commons", "Could not authenticate :(");
return;
} }
MWApi api = CommonsApplication.createMWApi(); MWApi api = CommonsApplication.createMWApi();