changeset 11864:d7ca3f02fe27

8144703: ClassCastException: sun.font.CompositeFont cannot be cast to PhysicalFont Reviewed-by: serb, alexp
author dmarkov
date Thu, 30 Jun 2016 11:54:35 +0300
parents 33b34611d0c3
children 62d80374d172
files src/share/classes/sun/font/CompositeFont.java
diffstat 1 files changed, 14 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/sun/font/CompositeFont.java	Wed Jun 29 10:32:05 2016 +0300
+++ b/src/share/classes/sun/font/CompositeFont.java	Thu Jun 30 11:54:35 2016 +0300
@@ -270,10 +270,21 @@
                 if (componentNames[slot] == null) {
                     componentNames[slot] = name;
                 } else if (!componentNames[slot].equalsIgnoreCase(name)) {
-                    components[slot] =
-                        (PhysicalFont) fm.findFont2D(componentNames[slot],
-                                                     style,
+                    /* If a component specifies the file with a bad font,
+                     * the corresponding slot will be initialized by
+                     * default physical font. In such case findFont2D may
+                     * return composite font which cannot be casted to
+                     * physical font.
+                     */
+                    try {
+                        components[slot] =
+                            (PhysicalFont) fm.findFont2D(componentNames[slot],
+                                                         style,
                                                 FontManager.PHYSICAL_FALLBACK);
+                    } catch (ClassCastException cce) {
+                        /* Assign default physical font to the slot */
+                        components[slot] = fm.getDefaultPhysicalFont();
+                    }
                 }
             }
             deferredInitialisation[slot] = false;