changeset 39537:b2d4ed0ff6b9

8144703: ClassCastException: sun.font.CompositeFont cannot be cast to PhysicalFont Reviewed-by: serb, alexp
author dmarkov
date Wed, 29 Jun 2016 11:38:29 +0300
parents 15aa85454ff5
children 8477ce4d6628
files jdk/src/java.desktop/share/classes/sun/font/CompositeFont.java
diffstat 1 files changed, 14 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- 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;