Exception in thread "main" java.lang.ClassCastException: class sun.font.CompositeFont cannot be cast to class sun.font.PhysicalFont (sun.font.CompositeFont and sun.font.PhysicalFont are in module java.desktop of loader 'bootstrap') with JAVA 11 on solaris sparc 64 bit. JDK Version :-- 11.0.2
While running our application with JDK 11.0.2 on Solaris Sparc 64 bit , we are getting this exception :-
Exception in thread "main" java.lang.ClassCastException: class sun.font.CompositeFont cannot be cast to class sun.font.PhysicalFont (sun.font.CompositeFont and sun.font.PhysicalFont are in module java.desktop of loader 'bootstrap')
at java.desktop/sun.font.SunFontManager.getDefaultPhysicalFont(SunFontManager.java:1086)
at java.desktop/sun.font.SunFontManager.initialiseDeferredFont(SunFontManager.java:965)
at java.desktop/sun.font.CompositeFont.doDeferredInitialisation(CompositeFont.java:287)
at java.desktop/sun.font.CompositeFont.getSlotFont(CompositeFont.java:376)
at java.desktop/sun.font.CompositeStrike.getStrikeForSlot(CompositeStrike.java:80)
at java.desktop/sun.font.CompositeStrike.getFontMetrics(CompositeStrike.java:95)
at java.desktop/sun.font.FontDesignMetrics.initMatrixAndMetrics(FontDesignMetrics.java:360)
at java.desktop/sun.font.FontDesignMetrics.<init>(FontDesignMetrics.java:351)
at java.desktop/sun.font.FontDesignMetrics.getMetrics(FontDesignMetrics.java:303)
at java.desktop/sun.swing.SwingUtilities2.getFontMetrics(SwingUtilities2.java:1231)
at java.desktop/javax.swing.JComponent.getFontMetrics(JComponent.java:1646)
at java.desktop/javax.swing.plaf.basic.BasicGraphicsUtils.getPreferredButtonSize(BasicGraphicsUtils.java:351)
at java.desktop/javax.swing.plaf.basic.BasicButtonUI.getPreferredSize(BasicButtonUI.java:474)
at java.desktop/javax.swing.JComponent.getPreferredSize(JComponent.java:1680)
int w = Math.max(74, toStartButton.getPreferredSize().width+2);
As per this JDK bug ID link :-- https://bugs.java.com/bugdatabase/view_bug.do?bug_id=8132850 it is reolved in JDK 8 and JDK 9 but still we are getting this issue on JDK 11. I double checked the CompositeFont.java class. There the condition is surrounded within try-catch block as mentioned in the solution but still it is not working.
please help.
There is another SO issue raised which is :- OpenJDK 11 java.lang.ClassCastException: class sun.font.CompositeFont cannot be cast to class sun.font.PhysicalFont