Skip to content

Commit 732a5f8

Browse files
authored
Add missing nullability annotations to Remote Config. (#608)
1 parent 1fa769c commit 732a5f8

9 files changed

+75
-30
lines changed

firebase-config/firebase-config.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ plugins {
2222
firebaseLibrary {
2323
testLab.enabled = true
2424
publishSources = true
25-
staticAnalysis.disableKotlinInteropLint()
2625
}
2726

2827
protobuf {

firebase-config/src/main/java/com/google/firebase/remoteconfig/FirebaseRemoteConfig.java

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,14 @@ public class FirebaseRemoteConfig {
7272
* @return A singleton instance of {@link FirebaseRemoteConfig} for the default {@link
7373
* FirebaseApp}.
7474
*/
75+
@NonNull
7576
public static FirebaseRemoteConfig getInstance() {
7677
return getInstance(FirebaseApp.getInstance());
7778
}
7879

7980
/** Returns an instance of Firebase Remote Config for the given {@link FirebaseApp}. */
80-
public static FirebaseRemoteConfig getInstance(FirebaseApp app) {
81+
@NonNull
82+
public static FirebaseRemoteConfig getInstance(@NonNull FirebaseApp app) {
8183
return app.get(RemoteConfigComponent.class).getDefault();
8284
}
8385

@@ -178,6 +180,7 @@ public static FirebaseRemoteConfig getInstance(FirebaseApp app) {
178180
* Returns a {@link Task} representing the initialization status of this Firebase Remote Config
179181
* instance.
180182
*/
183+
@NonNull
181184
public Task<FirebaseRemoteConfigInfo> ensureInitialized() {
182185
Task<ConfigContainer> activatedConfigsTask = activatedConfigsCache.get();
183186
Task<ConfigContainer> defaultsConfigsTask = defaultConfigsCache.get();
@@ -202,6 +205,7 @@ public Task<FirebaseRemoteConfigInfo> ensureInitialized() {
202205
* configs; if no configs were fetched from the backend and the local fetched configs have
203206
* already been activated, returns a {@link Task} with a {@code false} result.
204207
*/
208+
@NonNull
205209
public Task<Boolean> fetchAndActivate() {
206210
return fetch().onSuccessTask(executor, (unusedVoid) -> activate());
207211
}
@@ -248,6 +252,7 @@ public boolean activateFetched() {
248252
* configs; if the fetched configs were already activated by a previous call, returns a {@link
249253
* Task} with a {@code false} result.
250254
*/
255+
@NonNull
251256
public Task<Boolean> activate() {
252257
Task<ConfigContainer> fetchedConfigsTask = fetchedConfigsCache.get();
253258
Task<ConfigContainer> activatedConfigsTask = activatedConfigsCache.get();
@@ -293,6 +298,7 @@ public Task<Boolean> activate() {
293298
*
294299
* @return {@link Task} representing the {@code fetch} call.
295300
*/
301+
@NonNull
296302
public Task<Void> fetch() {
297303
Task<FetchResponse> fetchTask = fetchHandler.fetch();
298304

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

@@ -339,7 +346,8 @@ public Task<Void> fetch(long minimumFetchIntervalInSeconds) {
339346
* @return {@link String} representing the value of the Firebase Remote Config parameter with the
340347
* given key.
341348
*/
342-
public String getString(String key) {
349+
@NonNull
350+
public String getString(@NonNull String key) {
343351
return getHandler.getString(key);
344352
}
345353

@@ -364,7 +372,7 @@ public String getString(String key) {
364372
* @return {@code boolean} representing the value of the Firebase Remote Config parameter with the
365373
* given key.
366374
*/
367-
public boolean getBoolean(String key) {
375+
public boolean getBoolean(@NonNull String key) {
368376
return getHandler.getBoolean(key);
369377
}
370378

@@ -383,8 +391,9 @@ public boolean getBoolean(String key) {
383391
* @return {@code byte[]} representing the value of the Firebase Remote Config parameter with the
384392
* given key.
385393
*/
394+
@NonNull
386395
@Deprecated
387-
public byte[] getByteArray(String key) {
396+
public byte[] getByteArray(@NonNull String key) {
388397
return getHandler.getByteArray(key);
389398
}
390399

@@ -405,7 +414,7 @@ public byte[] getByteArray(String key) {
405414
* @return {@code double} representing the value of the Firebase Remote Config parameter with the
406415
* given key.
407416
*/
408-
public double getDouble(String key) {
417+
public double getDouble(@NonNull String key) {
409418
return getHandler.getDouble(key);
410419
}
411420

@@ -426,7 +435,7 @@ public double getDouble(String key) {
426435
* @return {@code long} representing the value of the Firebase Remote Config parameter with the
427436
* given key.
428437
*/
429-
public long getLong(String key) {
438+
public long getLong(@NonNull String key) {
430439
return getHandler.getLong(key);
431440
}
432441

@@ -445,7 +454,8 @@ public long getLong(String key) {
445454
* @return {@link FirebaseRemoteConfigValue} representing the value of the Firebase Remote Config
446455
* parameter with the given key.
447456
*/
448-
public FirebaseRemoteConfigValue getValue(String key) {
457+
@NonNull
458+
public FirebaseRemoteConfigValue getValue(@NonNull String key) {
449459
return getHandler.getValue(key);
450460
}
451461

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

@@ -469,6 +480,7 @@ public Set<String> getKeysByPrefix(String prefix) {
469480
* <li>The default value, if the key was set with {@link #setDefaultsAsync}.
470481
* </ol>
471482
*/
483+
@NonNull
472484
public Map<String, FirebaseRemoteConfigValue> getAll() {
473485
return getHandler.getAll();
474486
}
@@ -477,6 +489,7 @@ public Map<String, FirebaseRemoteConfigValue> getAll() {
477489
* Returns the state of this {@link FirebaseRemoteConfig} instance as a {@link
478490
* FirebaseRemoteConfigInfo}.
479491
*/
492+
@NonNull
480493
public FirebaseRemoteConfigInfo getInfo() {
481494
return frcMetadata.getInfo();
482495
}
@@ -488,7 +501,7 @@ public FirebaseRemoteConfigInfo getInfo() {
488501
* @deprecated Use {@link #setConfigSettingsAsync(FirebaseRemoteConfigSettings)} instead.
489502
*/
490503
@Deprecated
491-
public void setConfigSettings(FirebaseRemoteConfigSettings settings) {
504+
public void setConfigSettings(@NonNull FirebaseRemoteConfigSettings settings) {
492505
frcMetadata.setConfigSettingsWithoutWaitingOnDiskWrite(settings);
493506
}
494507

@@ -497,7 +510,8 @@ public void setConfigSettings(FirebaseRemoteConfigSettings settings) {
497510
*
498511
* @param settings The new settings to be applied.
499512
*/
500-
public Task<Void> setConfigSettingsAsync(FirebaseRemoteConfigSettings settings) {
513+
@NonNull
514+
public Task<Void> setConfigSettingsAsync(@NonNull FirebaseRemoteConfigSettings settings) {
501515
return Tasks.call(
502516
executor,
503517
() -> {
@@ -526,7 +540,7 @@ public Task<Void> setConfigSettingsAsync(FirebaseRemoteConfigSettings settings)
526540
* @deprecated Use {@link #setDefaultsAsync} instead.
527541
*/
528542
@Deprecated
529-
public void setDefaults(Map<String, Object> defaults) {
543+
public void setDefaults(@NonNull Map<String, Object> defaults) {
530544
// Fetch values from the server are in the Map<String, String> format, so match that here.
531545
Map<String, String> defaultsStringMap = new HashMap<>();
532546
for (Map.Entry<String, Object> defaultsEntry : defaults.entrySet()) {
@@ -552,7 +566,8 @@ public void setDefaults(Map<String, Object> defaults) {
552566
* @param defaults {@link Map} of key value pairs representing Firebase Remote Config parameter
553567
* keys and values.
554568
*/
555-
public Task<Void> setDefaultsAsync(Map<String, Object> defaults) {
569+
@NonNull
570+
public Task<Void> setDefaultsAsync(@NonNull Map<String, Object> defaults) {
556571
// Fetch values from the server are in the Map<String, String> format, so match that here.
557572
Map<String, String> defaultsStringMap = new HashMap<>();
558573
for (Map.Entry<String, Object> defaultsEntry : defaults.entrySet()) {
@@ -579,6 +594,7 @@ public void setDefaults(@XmlRes int resourceId) {
579594
* @param resourceId Id for the XML resource, which should be in your application's {@code
580595
* res/xml} folder.
581596
*/
597+
@NonNull
582598
public Task<Void> setDefaultsAsync(@XmlRes int resourceId) {
583599
Map<String, String> xmlDefaults = DefaultsXmlParser.getDefaultsFromXml(context, resourceId);
584600
return setDefaultsWithStringsMapAsync(xmlDefaults);
@@ -590,6 +606,7 @@ public Task<Void> setDefaultsAsync(@XmlRes int resourceId) {
590606
*
591607
* @return {@link Task} representing the {@code clear} call.
592608
*/
609+
@NonNull
593610
public Task<Void> reset() {
594611
// Use a Task to avoid throwing potential file I/O errors to the caller and because
595612
// frcMetadata's clear call is blocking.

firebase-config/src/main/java/com/google/firebase/remoteconfig/FirebaseRemoteConfigClientException.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414

1515
package com.google.firebase.remoteconfig;
1616

17+
import androidx.annotation.NonNull;
18+
import androidx.annotation.Nullable;
19+
1720
/**
1821
* A Firebase Remote Config internal issue that isn't caused by an interaction with the Firebase
1922
* Remote Config server.
@@ -22,12 +25,13 @@
2225
*/
2326
public class FirebaseRemoteConfigClientException extends FirebaseRemoteConfigException {
2427
/** Creates a Firebase Remote Config client exception with the given message. */
25-
public FirebaseRemoteConfigClientException(String detailMessage) {
28+
public FirebaseRemoteConfigClientException(@NonNull String detailMessage) {
2629
super(detailMessage);
2730
}
2831

2932
/** Creates a Firebase Remote Config client exception with the given message and cause. */
30-
public FirebaseRemoteConfigClientException(String detailMessage, Throwable cause) {
33+
public FirebaseRemoteConfigClientException(
34+
@NonNull String detailMessage, @Nullable Throwable cause) {
3135
super(detailMessage, cause);
3236
}
3337
}

firebase-config/src/main/java/com/google/firebase/remoteconfig/FirebaseRemoteConfigException.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,19 @@
1414

1515
package com.google.firebase.remoteconfig;
1616

17+
import androidx.annotation.NonNull;
18+
import androidx.annotation.Nullable;
1719
import com.google.firebase.FirebaseException;
1820

1921
/** Base class for {@link FirebaseRemoteConfig} exceptions. */
2022
public class FirebaseRemoteConfigException extends FirebaseException {
2123
/** Creates a Firebase Remote Config exception with the given message. */
22-
public FirebaseRemoteConfigException(String detailMessage) {
24+
public FirebaseRemoteConfigException(@NonNull String detailMessage) {
2325
super(detailMessage);
2426
}
2527

2628
/** Creates a Firebase Remote Config exception with the given message and cause. */
27-
public FirebaseRemoteConfigException(String detailMessage, Throwable cause) {
29+
public FirebaseRemoteConfigException(@NonNull String detailMessage, @Nullable Throwable cause) {
2830
super(detailMessage, cause);
2931
}
3032
}

firebase-config/src/main/java/com/google/firebase/remoteconfig/FirebaseRemoteConfigFetchException.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414

1515
package com.google.firebase.remoteconfig;
1616

17+
import androidx.annotation.NonNull;
18+
import androidx.annotation.Nullable;
19+
1720
/**
1821
* Exception thrown when the {@link FirebaseRemoteConfig#fetch()} operation cannot be completed
1922
* successfully.
@@ -24,12 +27,13 @@
2427
@Deprecated
2528
public class FirebaseRemoteConfigFetchException extends FirebaseRemoteConfigException {
2629
/** Creates a Firebase Remote Config fetch exception with the given message. */
27-
public FirebaseRemoteConfigFetchException(String detailMessage) {
30+
public FirebaseRemoteConfigFetchException(@NonNull String detailMessage) {
2831
super(detailMessage);
2932
}
3033

3134
/** Creates a Firebase Remote Config fetch exception with the given message and cause. */
32-
public FirebaseRemoteConfigFetchException(String detailMessage, Throwable cause) {
35+
public FirebaseRemoteConfigFetchException(
36+
@NonNull String detailMessage, @Nullable Throwable cause) {
3337
super(detailMessage, cause);
3438
}
3539
}

firebase-config/src/main/java/com/google/firebase/remoteconfig/FirebaseRemoteConfigInfo.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
package com.google.firebase.remoteconfig;
1616

17+
import androidx.annotation.NonNull;
18+
1719
/** Wraps the current state of the FirebaseRemoteConfig singleton object. */
1820
public interface FirebaseRemoteConfigInfo {
1921
/**
@@ -23,7 +25,7 @@ public interface FirebaseRemoteConfigInfo {
2325
* @return -1 if no fetch attempt has been made yet. Otherwise, returns the timestamp of the last
2426
* successful fetch operation.
2527
*/
26-
public long getFetchTimeMillis();
28+
long getFetchTimeMillis();
2729

2830
/**
2931
* Gets the status of the most recent fetch attempt.
@@ -33,12 +35,13 @@ public interface FirebaseRemoteConfigInfo {
3335
* FirebaseRemoteConfig#LAST_FETCH_STATUS_THROTTLED}, or {@link
3436
* FirebaseRemoteConfig#LAST_FETCH_STATUS_NO_FETCH_YET}.
3537
*/
36-
public int getLastFetchStatus();
38+
int getLastFetchStatus();
3739

3840
/**
3941
* Gets the current settings of the FirebaseRemoteConfig singleton object.
4042
*
4143
* @return A {@link FirebaseRemoteConfigSettings} object indicating the current settings.
4244
*/
43-
public FirebaseRemoteConfigSettings getConfigSettings();
45+
@NonNull
46+
FirebaseRemoteConfigSettings getConfigSettings();
4447
}

firebase-config/src/main/java/com/google/firebase/remoteconfig/FirebaseRemoteConfigServerException.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414

1515
package com.google.firebase.remoteconfig;
1616

17+
import androidx.annotation.NonNull;
18+
import androidx.annotation.Nullable;
19+
1720
/**
1821
* A Firebase Remote Config internal issue caused by an interaction with the Firebase Remote Config
1922
* server.
@@ -26,7 +29,7 @@ public class FirebaseRemoteConfigServerException extends FirebaseRemoteConfigExc
2629
/**
2730
* Creates a Firebase Remote Config server exception with the given message and HTTP status code.
2831
*/
29-
public FirebaseRemoteConfigServerException(int httpStatusCode, String detailMessage) {
32+
public FirebaseRemoteConfigServerException(int httpStatusCode, @NonNull String detailMessage) {
3033
super(detailMessage);
3134
this.httpStatusCode = httpStatusCode;
3235
}
@@ -35,7 +38,7 @@ public FirebaseRemoteConfigServerException(int httpStatusCode, String detailMess
3538
* Creates a Firebase Remote Config server exception with the given message, HTTP status code and
3639
*/
3740
public FirebaseRemoteConfigServerException(
38-
int httpStatusCode, String detailMessage, Throwable cause) {
41+
int httpStatusCode, @NonNull String detailMessage, @Nullable Throwable cause) {
3942
super(detailMessage, cause);
4043
this.httpStatusCode = httpStatusCode;
4144
}

firebase-config/src/main/java/com/google/firebase/remoteconfig/FirebaseRemoteConfigSettings.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import static com.google.firebase.remoteconfig.RemoteConfigComponent.NETWORK_CONNECTION_TIMEOUT_IN_SECONDS;
1818
import static com.google.firebase.remoteconfig.internal.ConfigFetchHandler.DEFAULT_MINIMUM_FETCH_INTERVAL_IN_SECONDS;
1919

20+
import androidx.annotation.NonNull;
21+
2022
/**
2123
* Wraps the settings for {@link FirebaseRemoteConfig} operations.
2224
*
@@ -60,6 +62,7 @@ public long getMinimumFetchIntervalInSeconds() {
6062
}
6163

6264
/** Constructs a builder initialized with the current FirebaseRemoteConfigSettings. */
65+
@NonNull
6366
public FirebaseRemoteConfigSettings.Builder toBuilder() {
6467
FirebaseRemoteConfigSettings.Builder frcBuilder = new FirebaseRemoteConfigSettings.Builder();
6568
frcBuilder.setDeveloperModeEnabled(this.isDeveloperModeEnabled());
@@ -82,6 +85,7 @@ public static class Builder {
8285
* setting.
8386
* @deprecated Use {@link #setMinimumFetchIntervalInSeconds(long)} instead.
8487
*/
88+
@NonNull
8589
@Deprecated
8690
public Builder setDeveloperModeEnabled(boolean enabled) {
8791
enableDeveloperMode = enabled;
@@ -97,6 +101,7 @@ public Builder setDeveloperModeEnabled(boolean enabled) {
97101
*
98102
* @param duration Timeout duration in seconds. Should be a non-negative number.
99103
*/
104+
@NonNull
100105
public Builder setFetchTimeoutInSeconds(long duration) throws IllegalArgumentException {
101106
if (duration < 0) {
102107
throw new IllegalArgumentException(
@@ -117,6 +122,7 @@ public Builder setFetchTimeoutInSeconds(long duration) throws IllegalArgumentExc
117122
*
118123
* @param duration Interval duration in seconds. Should be a non-negative number.
119124
*/
125+
@NonNull
120126
public Builder setMinimumFetchIntervalInSeconds(long duration) {
121127
if (duration < 0) {
122128
throw new IllegalArgumentException(
@@ -131,6 +137,7 @@ public Builder setMinimumFetchIntervalInSeconds(long duration) {
131137
/**
132138
* Returns a {@link FirebaseRemoteConfigSettings} with the settings provided to this builder.
133139
*/
140+
@NonNull
134141
public FirebaseRemoteConfigSettings build() {
135142
return new FirebaseRemoteConfigSettings(this);
136143
}

0 commit comments

Comments
 (0)