Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 51b12fe

Browse files
committed
Fix crash getting spell-check suggestions
1 parent 1942b0c commit 51b12fe

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

shell/platform/android/io/flutter/plugin/editing/SpellCheckPlugin.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ public void onGetSentenceSuggestions(SentenceSuggestionsInfo[] results) {
132132
ArrayList<HashMap<String, Object>> spellCheckerSuggestionSpans =
133133
new ArrayList<HashMap<String, Object>>();
134134
SentenceSuggestionsInfo spellCheckResults = results[0];
135+
if (spellCheckResults == null) {
136+
pendingResult.success(new ArrayList<HashMap<String, Object>>());
137+
pendingResult = null;
138+
return;
139+
}
135140

136141
for (int i = 0; i < spellCheckResults.getSuggestionsCount(); i++) {
137142
SuggestionsInfo suggestionsInfo = spellCheckResults.getSuggestionsInfoAt(i);

shell/platform/android/test/io/flutter/plugin/editing/SpellCheckPluginTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,4 +247,22 @@ public void onGetSentenceSuggestionsResultsWithSuccessAndNoResultsWhenSuggestion
247247

248248
verify(mockResult).success(new ArrayList<HashMap<String, Object>>());
249249
}
250+
251+
@Test
252+
public void onGetSentenceSuggestionsResultsWithSuccessAndNoResultsWhenSuggestionsAreInvalid2() {
253+
TextServicesManager fakeTextServicesManager = mock(TextServicesManager.class);
254+
SpellCheckChannel fakeSpellCheckChannel = mock(SpellCheckChannel.class);
255+
SpellCheckPlugin spellCheckPlugin =
256+
spy(new SpellCheckPlugin(fakeTextServicesManager, fakeSpellCheckChannel));
257+
MethodChannel.Result mockResult = mock(MethodChannel.Result.class);
258+
spellCheckPlugin.pendingResult = mockResult;
259+
260+
spellCheckPlugin.onGetSentenceSuggestions(
261+
new SentenceSuggestionsInfo[] {
262+
// This "suggestion" may be provided by the Samsung spell checker:
263+
null
264+
});
265+
266+
verify(mockResult).success(new ArrayList<HashMap<String, Object>>());
267+
}
250268
}

0 commit comments

Comments
 (0)