From 49973b7f21995cd3a93770abfd60e140dfbb70df Mon Sep 17 00:00:00 2001 From: Vladimir Kryachko Date: Fri, 12 Jul 2019 12:56:36 -0400 Subject: [PATCH] Add missing nullability annotations to Remote Config. --- firebase-config/firebase-config.gradle | 1 - .../remoteconfig/FirebaseRemoteConfig.java | 41 +++++++++++++------ .../FirebaseRemoteConfigClientException.java | 8 +++- .../FirebaseRemoteConfigException.java | 6 ++- .../FirebaseRemoteConfigFetchException.java | 8 +++- .../FirebaseRemoteConfigInfo.java | 9 ++-- .../FirebaseRemoteConfigServerException.java | 7 +++- .../FirebaseRemoteConfigSettings.java | 7 ++++ .../FirebaseRemoteConfigValue.java | 18 +++++--- 9 files changed, 75 insertions(+), 30 deletions(-) diff --git a/firebase-config/firebase-config.gradle b/firebase-config/firebase-config.gradle index 75c2c790a34..c2ae397f254 100644 --- a/firebase-config/firebase-config.gradle +++ b/firebase-config/firebase-config.gradle @@ -22,7 +22,6 @@ plugins { firebaseLibrary { testLab.enabled = true publishSources = true - staticAnalysis.disableKotlinInteropLint() } protobuf { diff --git a/firebase-config/src/main/java/com/google/firebase/remoteconfig/FirebaseRemoteConfig.java b/firebase-config/src/main/java/com/google/firebase/remoteconfig/FirebaseRemoteConfig.java index 507acc81e29..785a0e133d0 100644 --- a/firebase-config/src/main/java/com/google/firebase/remoteconfig/FirebaseRemoteConfig.java +++ b/firebase-config/src/main/java/com/google/firebase/remoteconfig/FirebaseRemoteConfig.java @@ -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(); } @@ -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 ensureInitialized() { Task activatedConfigsTask = activatedConfigsCache.get(); Task defaultsConfigsTask = defaultConfigsCache.get(); @@ -202,6 +205,7 @@ public Task 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 fetchAndActivate() { return fetch().onSuccessTask(executor, (unusedVoid) -> activate()); } @@ -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 activate() { Task fetchedConfigsTask = fetchedConfigsCache.get(); Task activatedConfigsTask = activatedConfigsCache.get(); @@ -293,6 +298,7 @@ public Task activate() { * * @return {@link Task} representing the {@code fetch} call. */ + @NonNull public Task fetch() { Task fetchTask = fetchHandler.fetch(); @@ -317,6 +323,7 @@ public Task 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 fetch(long minimumFetchIntervalInSeconds) { Task fetchTask = fetchHandler.fetch(minimumFetchIntervalInSeconds); @@ -339,7 +346,8 @@ public Task 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); } @@ -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); } @@ -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); } @@ -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); } @@ -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); } @@ -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); } @@ -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 getKeysByPrefix(String prefix) { + @NonNull + public Set getKeysByPrefix(@NonNull String prefix) { return getHandler.getKeysByPrefix(prefix); } @@ -469,6 +480,7 @@ public Set getKeysByPrefix(String prefix) { *
  • The default value, if the key was set with {@link #setDefaultsAsync}. * */ + @NonNull public Map getAll() { return getHandler.getAll(); } @@ -477,6 +489,7 @@ public Map getAll() { * Returns the state of this {@link FirebaseRemoteConfig} instance as a {@link * FirebaseRemoteConfigInfo}. */ + @NonNull public FirebaseRemoteConfigInfo getInfo() { return frcMetadata.getInfo(); } @@ -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); } @@ -497,7 +510,8 @@ public void setConfigSettings(FirebaseRemoteConfigSettings settings) { * * @param settings The new settings to be applied. */ - public Task setConfigSettingsAsync(FirebaseRemoteConfigSettings settings) { + @NonNull + public Task setConfigSettingsAsync(@NonNull FirebaseRemoteConfigSettings settings) { return Tasks.call( executor, () -> { @@ -526,7 +540,7 @@ public Task setConfigSettingsAsync(FirebaseRemoteConfigSettings settings) * @deprecated Use {@link #setDefaultsAsync} instead. */ @Deprecated - public void setDefaults(Map defaults) { + public void setDefaults(@NonNull Map defaults) { // Fetch values from the server are in the Map format, so match that here. Map defaultsStringMap = new HashMap<>(); for (Map.Entry defaultsEntry : defaults.entrySet()) { @@ -552,7 +566,8 @@ public void setDefaults(Map defaults) { * @param defaults {@link Map} of key value pairs representing Firebase Remote Config parameter * keys and values. */ - public Task setDefaultsAsync(Map defaults) { + @NonNull + public Task setDefaultsAsync(@NonNull Map defaults) { // Fetch values from the server are in the Map format, so match that here. Map defaultsStringMap = new HashMap<>(); for (Map.Entry defaultsEntry : defaults.entrySet()) { @@ -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 setDefaultsAsync(@XmlRes int resourceId) { Map xmlDefaults = DefaultsXmlParser.getDefaultsFromXml(context, resourceId); return setDefaultsWithStringsMapAsync(xmlDefaults); @@ -590,6 +606,7 @@ public Task setDefaultsAsync(@XmlRes int resourceId) { * * @return {@link Task} representing the {@code clear} call. */ + @NonNull public Task reset() { // Use a Task to avoid throwing potential file I/O errors to the caller and because // frcMetadata's clear call is blocking. diff --git a/firebase-config/src/main/java/com/google/firebase/remoteconfig/FirebaseRemoteConfigClientException.java b/firebase-config/src/main/java/com/google/firebase/remoteconfig/FirebaseRemoteConfigClientException.java index 52fce97463e..2693730259a 100644 --- a/firebase-config/src/main/java/com/google/firebase/remoteconfig/FirebaseRemoteConfigClientException.java +++ b/firebase-config/src/main/java/com/google/firebase/remoteconfig/FirebaseRemoteConfigClientException.java @@ -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. @@ -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); } } diff --git a/firebase-config/src/main/java/com/google/firebase/remoteconfig/FirebaseRemoteConfigException.java b/firebase-config/src/main/java/com/google/firebase/remoteconfig/FirebaseRemoteConfigException.java index 0f5f5cf665d..edba0cb9463 100644 --- a/firebase-config/src/main/java/com/google/firebase/remoteconfig/FirebaseRemoteConfigException.java +++ b/firebase-config/src/main/java/com/google/firebase/remoteconfig/FirebaseRemoteConfigException.java @@ -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); } } diff --git a/firebase-config/src/main/java/com/google/firebase/remoteconfig/FirebaseRemoteConfigFetchException.java b/firebase-config/src/main/java/com/google/firebase/remoteconfig/FirebaseRemoteConfigFetchException.java index 1646e3bd221..6479012f368 100644 --- a/firebase-config/src/main/java/com/google/firebase/remoteconfig/FirebaseRemoteConfigFetchException.java +++ b/firebase-config/src/main/java/com/google/firebase/remoteconfig/FirebaseRemoteConfigFetchException.java @@ -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. @@ -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); } } diff --git a/firebase-config/src/main/java/com/google/firebase/remoteconfig/FirebaseRemoteConfigInfo.java b/firebase-config/src/main/java/com/google/firebase/remoteconfig/FirebaseRemoteConfigInfo.java index 601844c3d09..00b32bf29cf 100644 --- a/firebase-config/src/main/java/com/google/firebase/remoteconfig/FirebaseRemoteConfigInfo.java +++ b/firebase-config/src/main/java/com/google/firebase/remoteconfig/FirebaseRemoteConfigInfo.java @@ -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 { /** @@ -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. @@ -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(); } diff --git a/firebase-config/src/main/java/com/google/firebase/remoteconfig/FirebaseRemoteConfigServerException.java b/firebase-config/src/main/java/com/google/firebase/remoteconfig/FirebaseRemoteConfigServerException.java index 4cf74401d5f..723ddd6a53b 100644 --- a/firebase-config/src/main/java/com/google/firebase/remoteconfig/FirebaseRemoteConfigServerException.java +++ b/firebase-config/src/main/java/com/google/firebase/remoteconfig/FirebaseRemoteConfigServerException.java @@ -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. @@ -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; } @@ -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; } diff --git a/firebase-config/src/main/java/com/google/firebase/remoteconfig/FirebaseRemoteConfigSettings.java b/firebase-config/src/main/java/com/google/firebase/remoteconfig/FirebaseRemoteConfigSettings.java index 0b6908c98ea..e1b32dfc9ed 100644 --- a/firebase-config/src/main/java/com/google/firebase/remoteconfig/FirebaseRemoteConfigSettings.java +++ b/firebase-config/src/main/java/com/google/firebase/remoteconfig/FirebaseRemoteConfigSettings.java @@ -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. * @@ -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()); @@ -82,6 +85,7 @@ public static class Builder { * setting. * @deprecated Use {@link #setMinimumFetchIntervalInSeconds(long)} instead. */ + @NonNull @Deprecated public Builder setDeveloperModeEnabled(boolean enabled) { enableDeveloperMode = enabled; @@ -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( @@ -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( @@ -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); } diff --git a/firebase-config/src/main/java/com/google/firebase/remoteconfig/FirebaseRemoteConfigValue.java b/firebase-config/src/main/java/com/google/firebase/remoteconfig/FirebaseRemoteConfigValue.java index 36d23dd8c00..0106f262283 100644 --- a/firebase-config/src/main/java/com/google/firebase/remoteconfig/FirebaseRemoteConfigValue.java +++ b/firebase-config/src/main/java/com/google/firebase/remoteconfig/FirebaseRemoteConfigValue.java @@ -14,6 +14,8 @@ package com.google.firebase.remoteconfig; +import androidx.annotation.NonNull; + /** Wrapper for a Remote Config parameter value, with methods to get it as different types. */ public interface FirebaseRemoteConfigValue { /** @@ -22,33 +24,37 @@ public interface FirebaseRemoteConfigValue { * @return long representation of this parameter value. * @throws IllegalArgumentException If the value cannot be converted to a long. */ - public long asLong() throws IllegalArgumentException; + long asLong() throws IllegalArgumentException; /** * Gets the value as a double. * * @return double representation of this parameter value. * @throws IllegalArgumentException If the value cannot be converted to a double. */ - public double asDouble() throws IllegalArgumentException; + double asDouble() throws IllegalArgumentException; + /** * Gets the value as a String. * * @return String representation of this parameter value. */ - public String asString(); + @NonNull + String asString(); + /** * Gets the value as a byte[]. * * @return byte[] representation of this parameter value. */ - public byte[] asByteArray(); + @NonNull + byte[] asByteArray(); /** * Gets the value as a boolean. * * @return boolean representation of this parameter value. * @throws IllegalArgumentException If the value cannot be converted to a boolean. */ - public boolean asBoolean() throws IllegalArgumentException; + boolean asBoolean() throws IllegalArgumentException; /** * Indicates at which source this value came from. @@ -58,5 +64,5 @@ public interface FirebaseRemoteConfigValue { * default, or {@link FirebaseRemoteConfig#VALUE_SOURCE_STATIC} if no value was found and a * static default value was returned instead. */ - public int getSource(); + int getSource(); }