8144703: ClassCastException: sun.font.CompositeFont cannot be cast to PhysicalFont
Reviewed-by: serb, alexp
--- 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;