Skip to content

Commit 46b3ced

Browse files
author
Athira M
committed
Return default value if evaluate config getter calls with invalid type for a field
1 parent 3255fd8 commit 46b3ced

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/main/java/com/google/firebase/remoteconfig/ServerConfig.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public final class ServerConfig {
3939
*/
4040
@NonNull
4141
public String getString(@NonNull String key) {
42-
return configValues.get(key).asString();
42+
return this.getValue(key).asString();
4343
}
4444

4545
/**
@@ -51,7 +51,7 @@ public String getString(@NonNull String key) {
5151
*/
5252
@NonNull
5353
public boolean getBoolean(@NonNull String key) {
54-
return Boolean.parseBoolean(getString(key));
54+
return this.getValue(key).asBoolean();
5555
}
5656

5757
/**
@@ -63,7 +63,7 @@ public boolean getBoolean(@NonNull String key) {
6363
*/
6464
@NonNull
6565
public long getLong(@NonNull String key) {
66-
return Long.parseLong(getString(key));
66+
return this.getValue(key).asLong();
6767
}
6868

6969
/**
@@ -75,7 +75,21 @@ public long getLong(@NonNull String key) {
7575
*/
7676
@NonNull
7777
public double getDouble(@NonNull String key) {
78-
return Double.parseDouble(getString(key));
78+
return this.getValue(key).asDouble();
7979
}
8080

81+
/**
82+
* Gets the {@link Value} for the given key. Ensures application logic will
83+
* always have a type-safe reference, even if the parameter is removed remotely.
84+
*
85+
* @param key The name of the parameter.
86+
* @return config value for the given key.
87+
*/
88+
@NonNull
89+
public Value getValue(String key) {
90+
if (configValues.containsKey(key)) {
91+
return configValues.get(key);
92+
}
93+
return new Value(Value.ValueSource.STATIC);
94+
}
8195
}

0 commit comments

Comments
 (0)