8144703: ClassCastException: sun.font.CompositeFont cannot be cast to PhysicalFont
authordmarkov
Wed, 29 Jun 2016 11:38:29 +0300
changeset 39537 b2d4ed0ff6b9
parent 39536 15aa85454ff5
child 39538 8477ce4d6628
8144703: ClassCastException: sun.font.CompositeFont cannot be cast to PhysicalFont Reviewed-by: serb, alexp
jdk/src/java.desktop/share/classes/sun/font/CompositeFont.java
--- a/jdk/src/java.desktop/share/classes/sun/font/CompositeFont.java	Wed Jun 29 12:22:38 2016 +0530
+++ b/jdk/src/java.desktop/share/classes/sun/font/CompositeFont.java	Wed Jun 29 11:38:29 2016 +0300
@@ -289,10 +289,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;