Skip to content

Commit

Permalink
update non-null annotations to fix NPE on kotlin (#344)
Browse files Browse the repository at this point in the history
  • Loading branch information
lbalmaceda committed Sep 16, 2020
1 parent 97934cf commit 053282a
Show file tree
Hide file tree
Showing 15 changed files with 17 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.VisibleForTesting;

import com.auth0.android.Auth0;
Expand Down Expand Up @@ -593,7 +594,7 @@ public ParameterizableRequest<UserProfile, AuthenticationException> tokenInfo(@N
* @return a request to start
*/
@NonNull
public DatabaseConnectionRequest<DatabaseUser, AuthenticationException> createUser(@NonNull String email, @NonNull String password, @NonNull String username, @NonNull String connection) {
public DatabaseConnectionRequest<DatabaseUser, AuthenticationException> createUser(@NonNull String email, @NonNull String password, @Nullable String username, @NonNull String connection) {
HttpUrl url = HttpUrl.parse(auth0.getDomainUrl()).newBuilder()
.addPathSegment(DB_CONNECTIONS_PATH)
.addPathSegment(SIGN_UP_PATH)
Expand Down Expand Up @@ -635,7 +636,6 @@ public DatabaseConnectionRequest<DatabaseUser, AuthenticationException> createUs
*/
@NonNull
public DatabaseConnectionRequest<DatabaseUser, AuthenticationException> createUser(@NonNull String email, @NonNull String password, @NonNull String connection) {
//noinspection ConstantConditions
return createUser(email, password, null, connection);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
package com.auth0.android.authentication.request;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import com.auth0.android.Auth0Exception;
import com.auth0.android.authentication.AuthenticationException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,13 @@ public void start(@NonNull final BaseCallback<Authentication, AuthenticationExce
getAuthRequest().start(new BaseCallback<Credentials, AuthenticationException>() {
@Override
public void onSuccess(@Nullable final Credentials credentials) {
//noinspection ConstantConditions
userInfoRequest
.addHeader(HEADER_AUTHORIZATION, "Bearer " + credentials.getAccessToken())
.start(new BaseCallback<UserProfile, AuthenticationException>() {
@Override
public void onSuccess(@Nullable UserProfile profile) {
//noinspection ConstantConditions
callback.onSuccess(new Authentication(profile, credentials));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ private void continueGetCredentials(final BaseCallback<Credentials, CredentialsM
@Override
public void onSuccess(@Nullable Credentials fresh) {
//non-empty refresh token for refresh token rotation scenarios
//noinspection ConstantConditions
String updatedRefreshToken = isEmpty(fresh.getRefreshToken()) ? credentials.getRefreshToken() : fresh.getRefreshToken();
Credentials refreshed = new Credentials(fresh.getIdToken(), fresh.getAccessToken(), fresh.getType(), updatedRefreshToken, fresh.getExpiresAt(), fresh.getScope());
saveCredentials(refreshed);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

package com.auth0.android.callback;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import com.auth0.android.Auth0Exception;

Expand All @@ -38,6 +38,6 @@ public interface BaseCallback<T, U extends Auth0Exception> extends Callback<U> {
*
* @param payload Request payload or null
*/
void onSuccess(@NonNull T payload);
void onSuccess(@Nullable T payload);

}
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ public void onFailure(@NonNull TokenValidationException error) {

@Override
public void onSuccess(@Nullable SignatureVerifier signatureVerifier) {
//noinspection ConstantConditions
IdTokenVerificationOptions options = new IdTokenVerificationOptions(idTokenVerificationIssuer, apiClient.getClientId(), signatureVerifier);
String maxAge = parameters.get(KEY_MAX_AGE);
if (!TextUtils.isEmpty(maxAge)) {
Expand Down
1 change: 1 addition & 0 deletions auth0/src/main/java/com/auth0/android/provider/PKCE.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public void getToken(String authorizationCode, @NonNull final AuthCallback callb
.start(new BaseCallback<Credentials, AuthenticationException>() {
@Override
public void onSuccess(@Nullable Credentials payload) {
//noinspection ConstantConditions
callback.onSuccess(payload);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ static void forAsymmetricAlgorithm(@Nullable final String keyId, @NonNull Authen
apiClient.fetchJsonWebKeys().start(new AuthenticationCallback<Map<String, PublicKey>>() {
@Override
public void onSuccess(@Nullable Map<String, PublicKey> jwks) {
//noinspection ConstantConditions
PublicKey publicKey = jwks.get(keyId);
try {
callback.onSuccess(new AsymmetricSignatureVerifier(publicKey));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@

package com.auth0.android.provider;

import android.support.annotation.Nullable;

import com.auth0.android.Auth0Exception;
import com.auth0.android.callback.BaseCallback;

Expand All @@ -34,6 +32,4 @@
*/
@SuppressWarnings("WeakerAccess")
public interface VoidCallback extends BaseCallback<Void, Auth0Exception> {
@Override
void onSuccess(@Nullable Void payload);
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ public void start(@NonNull Context context, @NonNull VoidCallback callback) {
if (returnToUrl == null) {
returnToUrl = CallbackHelper.getCallbackUri(scheme, context.getApplicationContext().getPackageName(), account.getDomainUrl());
}
//noinspection ConstantConditions
LogoutManager logoutManager = new LogoutManager(this.account, callback, returnToUrl);
logoutManager.setCustomTabsOptions(ctOptions);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.auth0.android.request.internal;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import com.auth0.android.Auth0Exception;
import com.auth0.android.management.ManagementException;
Expand Down Expand Up @@ -30,7 +31,7 @@ public ManagementException from(@NonNull Map<String, Object> values) {

@NonNull
@Override
public ManagementException from(@NonNull String payload, int statusCode) {
public ManagementException from(@Nullable String payload, int statusCode) {
return new ManagementException(payload, statusCode);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,6 @@ public void shouldNotSendNullUsernameOnSignUp() throws Exception {
mockAPI.willReturnSuccessfulSignUp();

final MockAuthenticationCallback<DatabaseUser> callback = new MockAuthenticationCallback<>();
//noinspection ConstantConditions
client.createUser(SUPPORT_AUTH0_COM, PASSWORD, null, MY_CONNECTION)
.start(callback);

Expand All @@ -864,7 +863,6 @@ public void shouldNotSendNullUsernameOnSignUp() throws Exception {
public void shouldNotSendNullUsernameOnSignUpSync() throws Exception {
mockAPI.willReturnSuccessfulSignUp();

//noinspection ConstantConditions
final DatabaseUser user = client.createUser(SUPPORT_AUTH0_COM, PASSWORD, null, MY_CONNECTION)
.execute();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,13 @@ public void shouldThrowOnSetIfCredentialsDoesNotHaveIdTokenOrAccessToken() {
manager.saveCredentials(credentials);
}

@SuppressWarnings("ConstantConditions")
@Test
public void shouldThrowOnSetIfCredentialsDoesNotHaveExpiresAt() {
exception.expect(CredentialsManagerException.class);
exception.expectMessage("Credentials must have a valid date of expiration and a valid access_token or id_token value.");

Date date = null;
//noinspection ConstantConditions
Credentials credentials = new CredentialsMock("idToken", "accessToken", "type", "refreshToken", date, "scope");
manager.saveCredentials(credentials);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,13 +277,13 @@ public void shouldThrowOnSaveIfCredentialsDoesNotHaveIdTokenOrAccessToken() {
manager.saveCredentials(credentials);
}

@SuppressWarnings("ConstantConditions")
@Test
public void shouldThrowOnSaveIfCredentialsDoesNotHaveExpiresAt() {
exception.expect(CredentialsManagerException.class);
exception.expectMessage("Credentials must have a valid date of expiration and a valid access_token or id_token value.");

Date date = null;
//noinspection ConstantConditions
Credentials credentials = new CredentialsMock("idToken", "accessToken", "type", "refreshToken", date, "scope");
prepareJwtDecoderMock(new Date());
manager.saveCredentials(credentials);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ public void shouldCreateWithCustomPreferencesFileName() {
verify(context).getSharedPreferences("my-preferences-file", Context.MODE_PRIVATE);
}

@SuppressWarnings("ConstantConditions")
@Test
public void shouldThrowOnCreateIfCustomPreferencesFileNameIsNull() {
exception.expect(IllegalArgumentException.class);
exception.expectMessage("The SharedPreferences name is invalid");
//noinspection ConstantConditions
new SharedPreferencesStorage(context, null);
}

Expand Down Expand Up @@ -184,11 +184,11 @@ public void shouldRetrieveBooleanValueFromPreferences() {

//Remove

@SuppressWarnings("ConstantConditions")
@Test
public void shouldRemovePreferencesKeyOnNullStringValue() {
SharedPreferencesStorage storage = new SharedPreferencesStorage(context);
String value = null;
//noinspection ConstantConditions
storage.store("name", value);
verify(sharedPreferencesEditor).remove("name");
verify(sharedPreferencesEditor).apply();
Expand Down

0 comments on commit 053282a

Please sign in to comment.