Skip to content

Commit 0ce098f

Browse files
DavidMina96HeshamMegid
authored andcommitted
[MOB-10972] Fix setValueForStringWithKey null exceptions (#310)
* Add a check for string key existence on Android * Add log message if a key doesn't exist on Android * Add a check for string key existence on iOS * Add log message if key doesn't exist on iOS * Update CHANGELOG.md
1 parent ffe2a7e commit 0ce098f

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## Unreleased
22

33
* Removes redundant native logs
4+
* Fixes a NullPointerException when overriding a string key that doesn't exist on Android
45

56
## 11.5.0 (2022-11-24)
67

android/src/main/java/com/instabug/flutter/modules/InstabugApi.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,14 @@ public void setSessionProfilerEnabled(@NonNull Boolean enabled) {
163163

164164
@Override
165165
public void setValueForStringWithKey(@NonNull String value, @NonNull String key) {
166-
InstabugCustomTextPlaceHolder.Key resolvedKey = ArgsRegistry.placeholders.get(key);
167-
placeHolder.set(resolvedKey, value);
168-
Instabug.setCustomTextPlaceHolders(placeHolder);
166+
if(ArgsRegistry.placeholders.containsKey(key)) {
167+
InstabugCustomTextPlaceHolder.Key resolvedKey = ArgsRegistry.placeholders.get(key);
168+
placeHolder.set(resolvedKey, value);
169+
Instabug.setCustomTextPlaceHolders(placeHolder);
170+
}
171+
else {
172+
Log.i(TAG, "Instabug: " + key + " is only relevant to iOS.");
173+
}
169174
}
170175

171176
@Override

ios/Classes/Modules/InstabugApi.m

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,14 @@ - (void)setSessionProfilerEnabledEnabled:(NSNumber *)enabled error:(FlutterError
9090
}
9191

9292
- (void)setValueForStringWithKeyValue:(NSString *)value key:(NSString *)key error:(FlutterError *_Nullable *_Nonnull)error {
93-
NSString *resolvedKey = ArgsRegistry.placeholders[key];
94-
[Instabug setValue:value forStringWithKey:resolvedKey];
93+
if ([ArgsRegistry.placeholders objectForKey:key]) {
94+
NSString *resolvedKey = ArgsRegistry.placeholders[key];
95+
[Instabug setValue:value forStringWithKey:resolvedKey];
96+
}
97+
else {
98+
NSString *logMessage = [NSString stringWithFormat: @"%@%@%@", @"Instabug: ", key, @" is only relevant to Android."];
99+
NSLog(@"%@", logMessage);
100+
}
95101
}
96102

97103
- (void)appendTagsTags:(NSArray<NSString *> *)tags error:(FlutterError *_Nullable *_Nonnull)error {

0 commit comments

Comments
 (0)