5

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

Jorn Vernee
  • 31,735
  • 4
  • 76
  • 93
user3820339
  • 151
  • 1
  • 4
  • 11
  • 2
    Can you duplicate it with a small test case? It would be good to get it into the bug database. – Alan Bateman Feb 13 '19 at 07:27
  • @AlanBateman please find the test case here :-- https://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8144703 – user3820339 May 03 '19 at 07:18
  • I encountered the same issue, and solved it here : https://stackoverflow.com/questions/55791235/pentaho-poi-throws-invocationtargetexception – Rudy May 28 '19 at 10:48
  • I'm facing the same issue with Oracle JDK11.0.5 (Not OpenJDK) with Solaris 64 bit, did anyone found a solution/workaround for this? seems like a bug to me. – Asela Senanayake Dec 17 '19 at 11:23

0 Answers0