Skip to content

Add missing nullability annotations to Remote Config. #608

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion firebase-config/firebase-config.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ plugins {
firebaseLibrary {
testLab.enabled = true
publishSources = true
staticAnalysis.disableKotlinInteropLint()
}

protobuf {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,14 @@ public class FirebaseRemoteConfig {
* @return A singleton instance of {@link FirebaseRemoteConfig} for the default {@link
* FirebaseApp}.
*/
@NonNull
public static FirebaseRemoteConfig getInstance() {
return getInstance(FirebaseApp.getInstance());
}

/** Returns an instance of Firebase Remote Config for the given {@link FirebaseApp}. */
public static FirebaseRemoteConfig getInstance(FirebaseApp app) {
@NonNull
public static FirebaseRemoteConfig getInstance(@NonNull FirebaseApp app) {
return app.get(RemoteConfigComponent.class).getDefault();
}

Expand Down Expand Up @@ -178,6 +180,7 @@ public static FirebaseRemoteConfig getInstance(FirebaseApp app) {
* Returns a {@link Task} representing the initialization status of this Firebase Remote Config
* instance.
*/
@NonNull
public Task<FirebaseRemoteConfigInfo> ensureInitialized() {
Task<ConfigContainer> activatedConfigsTask = activatedConfigsCache.get();
Task<ConfigContainer> defaultsConfigsTask = defaultConfigsCache.get();
Expand All @@ -202,6 +205,7 @@ public Task<FirebaseRemoteConfigInfo> ensureInitialized() {
* configs; if no configs were fetched from the backend and the local fetched configs have
* already been activated, returns a {@link Task} with a {@code false} result.
*/
@NonNull
public Task<Boolean> fetchAndActivate() {
return fetch().onSuccessTask(executor, (unusedVoid) -> activate());
}
Expand Down Expand Up @@ -248,6 +252,7 @@ public boolean activateFetched() {
* configs; if the fetched configs were already activated by a previous call, returns a {@link
* Task} with a {@code false} result.
*/
@NonNull
public Task<Boolean> activate() {
Task<ConfigContainer> fetchedConfigsTask = fetchedConfigsCache.get();
Task<ConfigContainer> activatedConfigsTask = activatedConfigsCache.get();
Expand Down Expand Up @@ -293,6 +298,7 @@ public Task<Boolean> activate() {
*
* @return {@link Task} representing the {@code fetch} call.
*/
@NonNull
public Task<Void> fetch() {
Task<FetchResponse> fetchTask = fetchHandler.fetch();

Expand All @@ -317,6 +323,7 @@ public Task<Void> fetch() {
* this many seconds ago, configs are served from the backend instead of local storage.
* @return {@link Task} representing the {@code fetch} call.
*/
@NonNull
public Task<Void> fetch(long minimumFetchIntervalInSeconds) {
Task<FetchResponse> fetchTask = fetchHandler.fetch(minimumFetchIntervalInSeconds);

Expand All @@ -339,7 +346,8 @@ public Task<Void> fetch(long minimumFetchIntervalInSeconds) {
* @return {@link String} representing the value of the Firebase Remote Config parameter with the
* given key.
*/
public String getString(String key) {
@NonNull
public String getString(@NonNull String key) {
return getHandler.getString(key);
}

Expand All @@ -364,7 +372,7 @@ public String getString(String key) {
* @return {@code boolean} representing the value of the Firebase Remote Config parameter with the
* given key.
*/
public boolean getBoolean(String key) {
public boolean getBoolean(@NonNull String key) {
return getHandler.getBoolean(key);
}

Expand All @@ -383,8 +391,9 @@ public boolean getBoolean(String key) {
* @return {@code byte[]} representing the value of the Firebase Remote Config parameter with the
* given key.
*/
@NonNull
@Deprecated
public byte[] getByteArray(String key) {
public byte[] getByteArray(@NonNull String key) {
return getHandler.getByteArray(key);
}

Expand All @@ -405,7 +414,7 @@ public byte[] getByteArray(String key) {
* @return {@code double} representing the value of the Firebase Remote Config parameter with the
* given key.
*/
public double getDouble(String key) {
public double getDouble(@NonNull String key) {
return getHandler.getDouble(key);
}

Expand All @@ -426,7 +435,7 @@ public double getDouble(String key) {
* @return {@code long} representing the value of the Firebase Remote Config parameter with the
* given key.
*/
public long getLong(String key) {
public long getLong(@NonNull String key) {
return getHandler.getLong(key);
}

Expand All @@ -445,7 +454,8 @@ public long getLong(String key) {
* @return {@link FirebaseRemoteConfigValue} representing the value of the Firebase Remote Config
* parameter with the given key.
*/
public FirebaseRemoteConfigValue getValue(String key) {
@NonNull
public FirebaseRemoteConfigValue getValue(@NonNull String key) {
return getHandler.getValue(key);
}

Expand All @@ -455,7 +465,8 @@ public FirebaseRemoteConfigValue getValue(String key) {
* @param prefix The key prefix to look for. If the prefix is empty, all keys are returned.
* @return {@link Set} of Remote Config parameter keys that start with the specified prefix.
*/
public Set<String> getKeysByPrefix(String prefix) {
@NonNull
public Set<String> getKeysByPrefix(@NonNull String prefix) {
return getHandler.getKeysByPrefix(prefix);
}

Expand All @@ -469,6 +480,7 @@ public Set<String> getKeysByPrefix(String prefix) {
* <li>The default value, if the key was set with {@link #setDefaultsAsync}.
* </ol>
*/
@NonNull
public Map<String, FirebaseRemoteConfigValue> getAll() {
return getHandler.getAll();
}
Expand All @@ -477,6 +489,7 @@ public Map<String, FirebaseRemoteConfigValue> getAll() {
* Returns the state of this {@link FirebaseRemoteConfig} instance as a {@link
* FirebaseRemoteConfigInfo}.
*/
@NonNull
public FirebaseRemoteConfigInfo getInfo() {
return frcMetadata.getInfo();
}
Expand All @@ -488,7 +501,7 @@ public FirebaseRemoteConfigInfo getInfo() {
* @deprecated Use {@link #setConfigSettingsAsync(FirebaseRemoteConfigSettings)} instead.
*/
@Deprecated
public void setConfigSettings(FirebaseRemoteConfigSettings settings) {
public void setConfigSettings(@NonNull FirebaseRemoteConfigSettings settings) {
frcMetadata.setConfigSettingsWithoutWaitingOnDiskWrite(settings);
}

Expand All @@ -497,7 +510,8 @@ public void setConfigSettings(FirebaseRemoteConfigSettings settings) {
*
* @param settings The new settings to be applied.
*/
public Task<Void> setConfigSettingsAsync(FirebaseRemoteConfigSettings settings) {
@NonNull
public Task<Void> setConfigSettingsAsync(@NonNull FirebaseRemoteConfigSettings settings) {
return Tasks.call(
executor,
() -> {
Expand Down Expand Up @@ -526,7 +540,7 @@ public Task<Void> setConfigSettingsAsync(FirebaseRemoteConfigSettings settings)
* @deprecated Use {@link #setDefaultsAsync} instead.
*/
@Deprecated
public void setDefaults(Map<String, Object> defaults) {
public void setDefaults(@NonNull Map<String, Object> defaults) {
// Fetch values from the server are in the Map<String, String> format, so match that here.
Map<String, String> defaultsStringMap = new HashMap<>();
for (Map.Entry<String, Object> defaultsEntry : defaults.entrySet()) {
Expand All @@ -552,7 +566,8 @@ public void setDefaults(Map<String, Object> defaults) {
* @param defaults {@link Map} of key value pairs representing Firebase Remote Config parameter
* keys and values.
*/
public Task<Void> setDefaultsAsync(Map<String, Object> defaults) {
@NonNull
public Task<Void> setDefaultsAsync(@NonNull Map<String, Object> defaults) {
// Fetch values from the server are in the Map<String, String> format, so match that here.
Map<String, String> defaultsStringMap = new HashMap<>();
for (Map.Entry<String, Object> defaultsEntry : defaults.entrySet()) {
Expand All @@ -579,6 +594,7 @@ public void setDefaults(@XmlRes int resourceId) {
* @param resourceId Id for the XML resource, which should be in your application's {@code
* res/xml} folder.
*/
@NonNull
public Task<Void> setDefaultsAsync(@XmlRes int resourceId) {
Map<String, String> xmlDefaults = DefaultsXmlParser.getDefaultsFromXml(context, resourceId);
return setDefaultsWithStringsMapAsync(xmlDefaults);
Expand All @@ -590,6 +606,7 @@ public Task<Void> setDefaultsAsync(@XmlRes int resourceId) {
*
* @return {@link Task} representing the {@code clear} call.
*/
@NonNull
public Task<Void> reset() {
// Use a Task to avoid throwing potential file I/O errors to the caller and because
// frcMetadata's clear call is blocking.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

package com.google.firebase.remoteconfig;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

/**
* A Firebase Remote Config internal issue that isn't caused by an interaction with the Firebase
* Remote Config server.
Expand All @@ -22,12 +25,13 @@
*/
public class FirebaseRemoteConfigClientException extends FirebaseRemoteConfigException {
/** Creates a Firebase Remote Config client exception with the given message. */
public FirebaseRemoteConfigClientException(String detailMessage) {
public FirebaseRemoteConfigClientException(@NonNull String detailMessage) {
super(detailMessage);
}

/** Creates a Firebase Remote Config client exception with the given message and cause. */
public FirebaseRemoteConfigClientException(String detailMessage, Throwable cause) {
public FirebaseRemoteConfigClientException(
@NonNull String detailMessage, @Nullable Throwable cause) {
super(detailMessage, cause);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,19 @@

package com.google.firebase.remoteconfig;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.google.firebase.FirebaseException;

/** Base class for {@link FirebaseRemoteConfig} exceptions. */
public class FirebaseRemoteConfigException extends FirebaseException {
/** Creates a Firebase Remote Config exception with the given message. */
public FirebaseRemoteConfigException(String detailMessage) {
public FirebaseRemoteConfigException(@NonNull String detailMessage) {
super(detailMessage);
}

/** Creates a Firebase Remote Config exception with the given message and cause. */
public FirebaseRemoteConfigException(String detailMessage, Throwable cause) {
public FirebaseRemoteConfigException(@NonNull String detailMessage, @Nullable Throwable cause) {
super(detailMessage, cause);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

package com.google.firebase.remoteconfig;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

/**
* Exception thrown when the {@link FirebaseRemoteConfig#fetch()} operation cannot be completed
* successfully.
Expand All @@ -24,12 +27,13 @@
@Deprecated
public class FirebaseRemoteConfigFetchException extends FirebaseRemoteConfigException {
/** Creates a Firebase Remote Config fetch exception with the given message. */
public FirebaseRemoteConfigFetchException(String detailMessage) {
public FirebaseRemoteConfigFetchException(@NonNull String detailMessage) {
super(detailMessage);
}

/** Creates a Firebase Remote Config fetch exception with the given message and cause. */
public FirebaseRemoteConfigFetchException(String detailMessage, Throwable cause) {
public FirebaseRemoteConfigFetchException(
@NonNull String detailMessage, @Nullable Throwable cause) {
super(detailMessage, cause);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

package com.google.firebase.remoteconfig;

import androidx.annotation.NonNull;

/** Wraps the current state of the FirebaseRemoteConfig singleton object. */
public interface FirebaseRemoteConfigInfo {
/**
Expand All @@ -23,7 +25,7 @@ public interface FirebaseRemoteConfigInfo {
* @return -1 if no fetch attempt has been made yet. Otherwise, returns the timestamp of the last
* successful fetch operation.
*/
public long getFetchTimeMillis();
long getFetchTimeMillis();

/**
* Gets the status of the most recent fetch attempt.
Expand All @@ -33,12 +35,13 @@ public interface FirebaseRemoteConfigInfo {
* FirebaseRemoteConfig#LAST_FETCH_STATUS_THROTTLED}, or {@link
* FirebaseRemoteConfig#LAST_FETCH_STATUS_NO_FETCH_YET}.
*/
public int getLastFetchStatus();
int getLastFetchStatus();

/**
* Gets the current settings of the FirebaseRemoteConfig singleton object.
*
* @return A {@link FirebaseRemoteConfigSettings} object indicating the current settings.
*/
public FirebaseRemoteConfigSettings getConfigSettings();
@NonNull
FirebaseRemoteConfigSettings getConfigSettings();
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

package com.google.firebase.remoteconfig;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

/**
* A Firebase Remote Config internal issue caused by an interaction with the Firebase Remote Config
* server.
Expand All @@ -26,7 +29,7 @@ public class FirebaseRemoteConfigServerException extends FirebaseRemoteConfigExc
/**
* Creates a Firebase Remote Config server exception with the given message and HTTP status code.
*/
public FirebaseRemoteConfigServerException(int httpStatusCode, String detailMessage) {
public FirebaseRemoteConfigServerException(int httpStatusCode, @NonNull String detailMessage) {
super(detailMessage);
this.httpStatusCode = httpStatusCode;
}
Expand All @@ -35,7 +38,7 @@ public FirebaseRemoteConfigServerException(int httpStatusCode, String detailMess
* Creates a Firebase Remote Config server exception with the given message, HTTP status code and
*/
public FirebaseRemoteConfigServerException(
int httpStatusCode, String detailMessage, Throwable cause) {
int httpStatusCode, @NonNull String detailMessage, @Nullable Throwable cause) {
super(detailMessage, cause);
this.httpStatusCode = httpStatusCode;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import static com.google.firebase.remoteconfig.RemoteConfigComponent.NETWORK_CONNECTION_TIMEOUT_IN_SECONDS;
import static com.google.firebase.remoteconfig.internal.ConfigFetchHandler.DEFAULT_MINIMUM_FETCH_INTERVAL_IN_SECONDS;

import androidx.annotation.NonNull;

/**
* Wraps the settings for {@link FirebaseRemoteConfig} operations.
*
Expand Down Expand Up @@ -60,6 +62,7 @@ public long getMinimumFetchIntervalInSeconds() {
}

/** Constructs a builder initialized with the current FirebaseRemoteConfigSettings. */
@NonNull
public FirebaseRemoteConfigSettings.Builder toBuilder() {
FirebaseRemoteConfigSettings.Builder frcBuilder = new FirebaseRemoteConfigSettings.Builder();
frcBuilder.setDeveloperModeEnabled(this.isDeveloperModeEnabled());
Expand All @@ -82,6 +85,7 @@ public static class Builder {
* setting.
* @deprecated Use {@link #setMinimumFetchIntervalInSeconds(long)} instead.
*/
@NonNull
@Deprecated
public Builder setDeveloperModeEnabled(boolean enabled) {
enableDeveloperMode = enabled;
Expand All @@ -97,6 +101,7 @@ public Builder setDeveloperModeEnabled(boolean enabled) {
*
* @param duration Timeout duration in seconds. Should be a non-negative number.
*/
@NonNull
public Builder setFetchTimeoutInSeconds(long duration) throws IllegalArgumentException {
if (duration < 0) {
throw new IllegalArgumentException(
Expand All @@ -117,6 +122,7 @@ public Builder setFetchTimeoutInSeconds(long duration) throws IllegalArgumentExc
*
* @param duration Interval duration in seconds. Should be a non-negative number.
*/
@NonNull
public Builder setMinimumFetchIntervalInSeconds(long duration) {
if (duration < 0) {
throw new IllegalArgumentException(
Expand All @@ -131,6 +137,7 @@ public Builder setMinimumFetchIntervalInSeconds(long duration) {
/**
* Returns a {@link FirebaseRemoteConfigSettings} with the settings provided to this builder.
*/
@NonNull
public FirebaseRemoteConfigSettings build() {
return new FirebaseRemoteConfigSettings(this);
}
Expand Down
Loading