Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash getting spell-check suggestions #42466

Merged
merged 1 commit into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ public void onGetSentenceSuggestions(SentenceSuggestionsInfo[] results) {
ArrayList<HashMap<String, Object>> spellCheckerSuggestionSpans =
new ArrayList<HashMap<String, Object>>();
SentenceSuggestionsInfo spellCheckResults = results[0];
if (spellCheckResults == null) {
pendingResult.success(new ArrayList<HashMap<String, Object>>());
pendingResult = null;
return;
}

for (int i = 0; i < spellCheckResults.getSuggestionsCount(); i++) {
SuggestionsInfo suggestionsInfo = spellCheckResults.getSuggestionsInfoAt(i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,22 @@ public void onGetSentenceSuggestionsResultsWithSuccessAndNoResultsWhenSuggestion

verify(mockResult).success(new ArrayList<HashMap<String, Object>>());
}

@Test
public void onGetSentenceSuggestionsResultsWithSuccessAndNoResultsWhenSuggestionsAreInvalid2() {
TextServicesManager fakeTextServicesManager = mock(TextServicesManager.class);
SpellCheckChannel fakeSpellCheckChannel = mock(SpellCheckChannel.class);
SpellCheckPlugin spellCheckPlugin =
spy(new SpellCheckPlugin(fakeTextServicesManager, fakeSpellCheckChannel));
MethodChannel.Result mockResult = mock(MethodChannel.Result.class);
spellCheckPlugin.pendingResult = mockResult;

spellCheckPlugin.onGetSentenceSuggestions(
new SentenceSuggestionsInfo[] {
// This "suggestion" may be provided by the Samsung spell checker:
null
});

verify(mockResult).success(new ArrayList<HashMap<String, Object>>());
}
}