From 91d558f398193dc69f48ba3dd9229c654d92e86b Mon Sep 17 00:00:00 2001 From: Callum Moffat Date: Wed, 31 May 2023 20:34:41 -0400 Subject: [PATCH] Fix crash getting spell-check suggestions --- .../plugin/editing/SpellCheckPlugin.java | 5 +++++ .../plugin/editing/SpellCheckPluginTest.java | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/shell/platform/android/io/flutter/plugin/editing/SpellCheckPlugin.java b/shell/platform/android/io/flutter/plugin/editing/SpellCheckPlugin.java index 5688e4fd597ae..37ee23cfe6f20 100644 --- a/shell/platform/android/io/flutter/plugin/editing/SpellCheckPlugin.java +++ b/shell/platform/android/io/flutter/plugin/editing/SpellCheckPlugin.java @@ -132,6 +132,11 @@ public void onGetSentenceSuggestions(SentenceSuggestionsInfo[] results) { ArrayList> spellCheckerSuggestionSpans = new ArrayList>(); SentenceSuggestionsInfo spellCheckResults = results[0]; + if (spellCheckResults == null) { + pendingResult.success(new ArrayList>()); + pendingResult = null; + return; + } for (int i = 0; i < spellCheckResults.getSuggestionsCount(); i++) { SuggestionsInfo suggestionsInfo = spellCheckResults.getSuggestionsInfoAt(i); diff --git a/shell/platform/android/test/io/flutter/plugin/editing/SpellCheckPluginTest.java b/shell/platform/android/test/io/flutter/plugin/editing/SpellCheckPluginTest.java index 97a28a0ca22d7..f5c1a6fb6ee23 100644 --- a/shell/platform/android/test/io/flutter/plugin/editing/SpellCheckPluginTest.java +++ b/shell/platform/android/test/io/flutter/plugin/editing/SpellCheckPluginTest.java @@ -247,4 +247,22 @@ public void onGetSentenceSuggestionsResultsWithSuccessAndNoResultsWhenSuggestion verify(mockResult).success(new ArrayList>()); } + + @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>()); + } }