OSDN Git Service

Ignore non-font resource references in TextView constructor
authorClara Bayarri <clarabayarri@google.com>
Fri, 3 Mar 2017 18:13:28 +0000 (18:13 +0000)
committerClara Bayarri <clarabayarri@google.com>
Fri, 3 Mar 2017 18:13:28 +0000 (18:13 +0000)
TextView was blowing up in its constructor when fontFamily was
set in xml to a reference that was not a font, e.g. @style/mystyle.

These values should be ignored as they are not valid, but we don't
want to crash the app for it either.

Bug: 35863153
Test: See topic
run cts -m CtsWidgetTestCases -t android.widget.cts.TextViewTest#testFontResources_setInXmlStyle

Change-Id: I5d9443e70a36122d312c3a9f2c0dcffb530dbca8

core/java/android/widget/TextView.java

index 051ffee..850ac71 100644 (file)
@@ -871,7 +871,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
                     case com.android.internal.R.styleable.TextAppearance_fontFamily:
                         try {
                             fontTypeface = appearance.getFont(attr);
-                        } catch (UnsupportedOperationException e) {
+                        } catch (UnsupportedOperationException | Resources.NotFoundException e) {
                             // Expected if it is not a font resource.
                         }
                         if (fontTypeface == null) {
@@ -1185,8 +1185,9 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
                 case com.android.internal.R.styleable.TextView_fontFamily:
                     try {
                         fontTypeface = a.getFont(attr);
-                    } catch (UnsupportedOperationException e) {
-                        // Expected if it is not a font resource.
+                    } catch (UnsupportedOperationException | Resources.NotFoundException e) {
+                        // Expected if it is not a resource reference or if it is a reference to
+                        // another resource type.
                     }
                     if (fontTypeface == null) {
                         fontFamily = a.getString(attr);
@@ -3312,7 +3313,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
         String fontFamily = null;
         try {
             fontTypeface = ta.getFont(R.styleable.TextAppearance_fontFamily);
-        } catch (UnsupportedOperationException e) {
+        } catch (UnsupportedOperationException | Resources.NotFoundException e) {
             // Expected if it is not a font resource.
         }
         if (fontTypeface == null) {