Fix NPE in PunctuationSuggestions.
The NPE happens when the keyboard doesn't specify any punctuation suggestions. Bug 18047927. Change-Id: I9f8aa35df4f163b527dc6580a99afc6da45a96b8
This commit is contained in:
parent
da27faeb87
commit
303a2ae5c9
1 changed files with 11 additions and 5 deletions
|
@ -23,6 +23,8 @@ import com.android.inputmethod.latin.common.StringUtils;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The extended {@link SuggestedWords} class to represent punctuation suggestions.
|
* The extended {@link SuggestedWords} class to represent punctuation suggestions.
|
||||||
*
|
*
|
||||||
|
@ -49,12 +51,16 @@ public final class PunctuationSuggestions extends SuggestedWords {
|
||||||
* @return The {@link PunctuationSuggestions} object.
|
* @return The {@link PunctuationSuggestions} object.
|
||||||
*/
|
*/
|
||||||
public static PunctuationSuggestions newPunctuationSuggestions(
|
public static PunctuationSuggestions newPunctuationSuggestions(
|
||||||
final String[] punctuationSpecs) {
|
@Nullable final String[] punctuationSpecs) {
|
||||||
final ArrayList<SuggestedWordInfo> puncuationsList = new ArrayList<>();
|
if (punctuationSpecs == null || punctuationSpecs.length == 0) {
|
||||||
for (final String puncSpec : punctuationSpecs) {
|
return new PunctuationSuggestions(new ArrayList<SuggestedWordInfo>(0));
|
||||||
puncuationsList.add(newHardCodedWordInfo(puncSpec));
|
|
||||||
}
|
}
|
||||||
return new PunctuationSuggestions(puncuationsList);
|
final ArrayList<SuggestedWordInfo> punctuationList =
|
||||||
|
new ArrayList<>(punctuationSpecs.length);
|
||||||
|
for (String spec : punctuationSpecs) {
|
||||||
|
punctuationList.add(newHardCodedWordInfo(spec));
|
||||||
|
}
|
||||||
|
return new PunctuationSuggestions(punctuationList);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue