Skip to content

Commit 89f2e8a

Browse files
Gilles DebunneAndroid (Google) Code Review
authored andcommitted
Merge "Prevent NPE in SuggestionSpan" into ics-mr1
2 parents a693a4b + c5436f2 commit 89f2e8a

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

core/java/android/text/style/SuggestionSpan.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,6 @@ public class SuggestionSpan extends CharacterStyle implements ParcelableSpan {
9292
private float mAutoCorrectionUnderlineThickness;
9393
private int mAutoCorrectionUnderlineColor;
9494

95-
/*
96-
* TODO: If switching IME is required, needs to add parameters for ids of InputMethodInfo
97-
* and InputMethodSubtype.
98-
*/
99-
10095
/**
10196
* @param context Context for the application
10297
* @param suggestions Suggestions for the string under the span
@@ -146,6 +141,16 @@ public SuggestionSpan(Context context, Locale locale, String[] suggestions, int
146141
}
147142

148143
private void initStyle(Context context) {
144+
if (context == null) {
145+
mMisspelledUnderlineThickness = 0;
146+
mEasyCorrectUnderlineThickness = 0;
147+
mAutoCorrectionUnderlineThickness = 0;
148+
mMisspelledUnderlineColor = Color.BLACK;
149+
mEasyCorrectUnderlineColor = Color.BLACK;
150+
mAutoCorrectionUnderlineColor = Color.BLACK;
151+
return;
152+
}
153+
149154
int defStyle = com.android.internal.R.attr.textAppearanceMisspelledSuggestion;
150155
TypedArray typedArray = context.obtainStyledAttributes(
151156
null, com.android.internal.R.styleable.SuggestionSpan, defStyle, 0);
@@ -169,7 +174,6 @@ private void initStyle(Context context) {
169174
com.android.internal.R.styleable.SuggestionSpan_textUnderlineThickness, 0);
170175
mAutoCorrectionUnderlineColor = typedArray.getColor(
171176
com.android.internal.R.styleable.SuggestionSpan_textUnderlineColor, Color.BLACK);
172-
173177
}
174178

175179
public SuggestionSpan(Parcel src) {

0 commit comments

Comments
 (0)