Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8221741

ClassCastException can happen when fontconfig.properties is used

    XMLWordPrintable

Details

    • 2d
    • b10
    • linux, aix

    Backports

      Description

        Following exception happened when fontconfig.properties (fontconfig.bfc) file was used and font setting was NOT configured via fontconfig:
        =======
        Exception in thread "AWT-EventQueue-0" 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:1081)
                at java.desktop/sun.font.SunFontManager.initialiseDeferredFont(SunFontManager.java:960)
                at java.desktop/sun.font.SunFontManager.findOtherDeferredFont(SunFontManager.java:898)
                at java.desktop/sun.font.SunFontManager.findDeferredFont(SunFontManager.java:914)
                at java.desktop/sun.font.SunFontManager.findFont2D(SunFontManager.java:2105)
                at java.desktop/java.awt.Font.getFont2D(Font.java:500)
                at java.desktop/java.awt.Font$FontAccessImpl.getFont2D(Font.java:237)
                at java.desktop/sun.font.FontUtilities.getFont2D(FontUtilities.java:139)
                at java.desktop/sun.font.FontUtilities.fontSupportsDefaultEncoding(FontUtilities.java:316)
        =======

        I could recreate by attached testcase on Linux platform.
        In case of AIX platform without fontconfig, defaultFontName was defined as "Dialog".

        $ $HOME/jdk-14+16/bin/java --add-opens java.desktop/sun.font=ALL-UNNAMED DefaultFontTest
        Exception in thread "main" java.lang.reflect.InvocationTargetException
                at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
                at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                at java.base/java.lang.reflect.Method.invoke(Method.java:564)
                at DefaultFontTest.main(DefaultFontTest.java:47)
        Caused by: 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:1081)
                ... 5 more

        Fixed test result on RHEL7.6 was as follows:
        $ java -Dsun.awt.fontconfig=$HOME/fontconfig.properties --add-opens java.desktop/sun.font=ALL-UNNAMED DefaultFontTest
        ** Type1 Font: Family=Courier 10 Pitch Name=Courier 10 Pitch style=0 fileName=/usr/share/X11/fonts/Type1/c0419bt_.pfb

        If Dialog font's slot 0 was missing
        $ java -Dsun.awt.fontconfig=$HOME/fontconfig.properties.bad --add-opens java.desktop/sun.font=ALL-UNNAMED DefaultFontTest
        ** Type1 Font: Family=Bitstream Charter Name=Bitstream Charter style=0 fileName=/usr/share/X11/fonts/Type1/c0648bt_.pfb

        Note:
        Please change font file name if you are using non RHEL7.6.

        JTreg test results for webrev.05 were as follows:
        Without FIX
        $ jtreg -v DefaultFontTest.java
        runner starting test: java/awt/font/DefaultFontTest/DefaultFontTest.java
        runner finished test: java/awt/font/DefaultFontTest/DefaultFontTest.java
        Failed. Execution failed: `main' threw exception: 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')
        Test results: failed: 1

        With FIX
        $ jtreg -v DefaultFontTest.java
        runner starting test: java/awt/font/DefaultFontTest/DefaultFontTest.java
        runner finished test: java/awt/font/DefaultFontTest/DefaultFontTest.java
        Passed. Execution successful
        Test results: passed: 1

        The fix was posted by:
        https://mail.openjdk.java.net/pipermail/2d-dev/2019-October/010324.html

        Attachments

          Issue Links

            Activity

              People

                clanger Christoph Langer
                itakiguchi Ichiroh Takiguchi
                Votes:
                0 Vote for this issue
                Watchers:
                8 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: