Here you are seeing the exception during initialisation but if the font is in use
we might get an exception handed to native code when it has not had to deal
with that. We should check that code and if it is ready to deal with pending
exceptions. Other JNI calls in native will fail if it is not and the exception will ultimately propagate back to the original Java code. It all needs to be looked through for problems.

-phil.

On 12/19/19 12:39 PM, Langer, Christoph wrote:

I don’t understand what’s intriguing you with that code, please help me…

It was done like this before, e.g. the RandomAccessFile was opened in the privileged block. But before you’d only see a null reference coming out in case something went wrong. Now you’d have the FileNotFoundException at hand to be able to trace this detail… Are you concerned that this information could be leaked out of the Privileged block when it shouldn’t?

/Christoph

*From:*Phil Race <philip.r...@oracle.com>
*Sent:* Donnerstag, 19. Dezember 2019 21:04
*To:* Langer, Christoph <christoph.lan...@sap.com>; Ichiroh Takiguchi <taki...@linux.vnet.ibm.com>
*Cc:* 2d-dev@openjdk.java.net
*Subject:* Re: [OpenJDK 2D-Dev] RFR: 8221741 ClassCastException happen when fontconfig.properties was used

This makes me very nervous because it is up-called from native code.
I am not sure I would want this change in any release ...

317             try {
318                 RandomAccessFile raf = AccessController.doPrivileged(
319                     new PrivilegedExceptionAction<RandomAccessFile>() { 320                         public RandomAccessFile run() throws FileNotFoundException { 321                             return new RandomAccessFile(platName, "r");


-phil.

On 12/19/19 12:01 PM, Langer, Christoph wrote:

    Hi Phil,

    Type 1 fonts were available but got skipped.

    /Christoph

        -----Original Message-----

        From: Phil Race<philip.r...@oracle.com>  <mailto:philip.r...@oracle.com>

        Sent: Donnerstag, 19. Dezember 2019 20:58

        To: Langer, Christoph<christoph.lan...@sap.com>  
<mailto:christoph.lan...@sap.com>; Ichiroh Takiguchi

        <taki...@linux.vnet.ibm.com>  <mailto:taki...@linux.vnet.ibm.com>

        Cc:2d-dev@openjdk.java.net  <mailto:2d-dev@openjdk.java.net>

        Subject: Re: [OpenJDK 2D-Dev] RFR: 8221741 ClassCastException happen

        when fontconfig.properties was used

        Hi,

            If this can get reviewed, I intend to push this fix to JDK14.

        Not for 14. This will take some time to review and test and is too 
risky at this

        stage.

        You say no TrueType fonts are installed, does that mean there are no

        scaleable fonts at all,

        or are there Type 1 fonts we are skipping over ?

        -phil.

        On 12/18/19 6:31 AM, Langer, Christoph wrote:

            Hi,

            sorry for the long time that it took me to come back to this item.

            I eventually spent quite a significant amount of time analyzing 
what's going

        wrong here. At least, I have a few AIX LPARs, where we would always

        encounter this type of Exception:

            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(SunFontMa

        nager.java:1081)

                      at

        java.desktop/sun.font.SunFontManager.initialiseDeferredFont(SunFontMan

        ager.java:960)

                      at

        java.desktop/sun.font.SunFontManager.findOtherDeferredFont(SunFontM

        anager.java:898)

                      at

        java.desktop/sun.font.SunFontManager.findDeferredFont(SunFontManager

        .java:914)

                      at

        java.desktop/sun.font.SunFontManager.findFont2D(SunFontManager.java:2

        105)

                      ...

            The problem on our systems is triggered by two factors. First is 
that the

        font configuration file contains paths to font files that don't exist. 
Secondly,

        the system's fontconfig has no TrueType Fonts installed. Now, during 
loading

        of fonts, it goes over these non-existing font files and tries to mark 
their

        initialization in sun.font.SunFontManager::initialiseDeferredFont(String

        fileNameKey) by adding the key into the initialisedFonts map. Since 
there is

        no font handle available because the font couldn't be loaded but the 
map's

        value must not be null, it wants to use the handle of the default 
physical

        font. So, calling getDefaultPhysicalFont at this place triggers 
findFont2D and

        then recursive calls into

        initialiseDeferredFont/getDefaultPhysicalFont/findFont2D until a 
matching

        default physical font was loaded. But it's quite indeterministic which 
font is

        returned at what place in findFont2D when the recursion is unwinded, so 
this

        ClassCastException occurs.

            I propose to fix this by adding a "NULL FONT HANDLE" to use in

        initialisedFonts for fonts that can’t be loaded. This will remove the 
recursion

        during loading of fonts. And afterwards a default physical font can 
then still

        be resolved, even if our font configuration contains less fonts (no 
true type

        fonts).

            In my change I also add small improvements to the exception cases 
when

        trying to load non-existent true type fonts and to method

        getDefaultPhysicalFont.

            The test exercises font loading and it would demonstrate the issue 
without

        the fix on several of our AIX systems.

            Here is the webrev:

        http://cr.openjdk.java.net/~clanger/webrevs/8221741.0/

            @Ichiroh-san: Can you test this fix in your environment and let me 
know if

        it fixes your issue?

            I'll run a full platform test here at SAP, including JDK11.

            If this can get reviewed, I intend to push this fix to JDK14.

            Thanks & Best regards

            Christoph

                -----Original Message-----

                From: Phil Race<philip.r...@oracle.com>  
<mailto:philip.r...@oracle.com>

                Sent: Mittwoch, 30. Oktober 2019 17:07

                To: Langer, Christoph<christoph.lan...@sap.com>  
<mailto:christoph.lan...@sap.com>; Ichiroh Takiguchi

                <taki...@linux.vnet.ibm.com>  
<mailto:taki...@linux.vnet.ibm.com>

                Cc:2d-dev@openjdk.java.net  <mailto:2d-dev@openjdk.java.net>; Zeller, 
Arno<arno.zel...@sap.com>  <mailto:arno.zel...@sap.com>

                Subject: Re: [OpenJDK 2D-Dev] RFR: 8221741 ClassCastException 
happen

                when fontconfig.properties was used

                Yes probably best if this is reviewed and approved by someone 
who

                has access to AIX. I have no idea if the XLFDs are even correct 
...

                -phil.

                On 10/30/19 8:00 AM, Langer, Christoph wrote:

                    Hi Ichiroh,

                    I'm currently observing a test issue on one of our AIX 
boxes with that

        patch

                in place. Please give me some time to have a closer look...

                    Best regards

                    Christoph

                        -----Original Message-----

                        From: 2d-dev<2d-dev-boun...@openjdk.java.net>  
<mailto:2d-dev-boun...@openjdk.java.net>  On Behalf Of

        Ichiroh

                        Takiguchi

                        Sent: Montag, 28. Oktober 2019 17:59

                        To: Philip Race<philip.r...@oracle.com>  
<mailto:philip.r...@oracle.com>

                        Cc:2d-dev@openjdk.java.net  <mailto:2d-dev@openjdk.java.net>; 
Zeller, Arno<arno.zel...@sap.com>  <mailto:arno.zel...@sap.com>

                        Subject: Re: [OpenJDK 2D-Dev] RFR: 8221741 
ClassCastException

        happen

                        when fontconfig.properties was used

                        Hello Phil and other reviewers.

                        I appreciate if you give me your comment and suggestion.

                        Thanks,

                        Ichiroh Takiguchi

                        On 2019-10-15 20:33, Ichiroh Takiguchi wrote:

                            Hello Phil.

                            Sorry for bad response.

                            AIX is following case, but physical font is not 
defined by default.

                                If you have fonts installed and have a custom 
fontconfig.properties

                                file for AIX

                                which references those, then you should be able 
to get a default

        font

                                from that

                                set of known existent physical fonts.

                            Please try following steps to emulate same kind 
this on linux (RHEL7).

                            1. Download DefaultFontTestA.java and 
fontconfig.properties files

                                  Please modify fontconfig.properties if 
c0419bt_.pfb is not in

                            /usr/share/X11/fonts/Type1 directory.

                            2. Compile and run with following options and 
environment variable.

                                   $ javac --add-exports 
java.desktop/sun.font=ALL-UNNAMED

                            DefaultFontTestA.java

                                   $ USE_J2D_FONTCONFIG=no java --add-opens

                            java.desktop/sun.font=ALL-UNNAMED

                            -Dsun.awt.fontconfigfontconfig.properties 
DefaultFontTestA

                                   defaultFontName=Dialog

                                   defaultFontFileName=/dialog.ttf

                                   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(SunFontMa

                        nager.java:1081)

                                           at 
DefaultFontTestA.main(DefaultFontTestA.java:48)

                                      Font2D font2d =

                                           findFont2D(getDefaultFontFaceName(), 
Font.PLAIN,

                            NO_FALLBACK);

                                 Note:

                                   USE_J2D_FONTCONFIG is defined into

                            src/java.desktop/unix/native/common/awt/fontpath.c

                                   Dialog and /dialog.ttf are defined into

                            
src/java.desktop/unix/classes/sun/awt/FcFontManager.java

                            getDefaultFontFaceName returns defaultFontName, it's 
"Dialog".

                            findFont2D() returns Dialog CompositeFont instead 
of physical font.

                            I think we cannot control return value for

                            physicalFonts.values().iterator();

                            "defaultPhysicalFont = ((CompositeFont) 
font2d).getSlotFont(0);" is

                            useful.

                            Please give me your comment.

                            Thanks,

                            Ichiroh Takiguchi

                            On 2019-10-09 01:06, Philip Race wrote:

                                I think this needs a little bit more 
explanation first.

                                Systems without fontconfig ... meaning without 
libfontconfig.

                                So does that mean you just can't find fonts or 
have none installed ?

                                If you have fonts installed and have a custom 
fontconfig.properties

                                file for AIX

                                which references those, then you should be able 
to get a default

        font

                                from that

                                set of known existent physical fonts.

                                If you have neither .. then you have a system 
configuration problem

                                and without

                                a physical font installed avoiding an exception 
here isn't really

                                going to help you

                                get much further. Perhaps we should throw 
InternalError a bit

        earlier.

                                I see no point in trying to survive ..

                                -phil

                                On 10/8/19, 12:35 AM, Langer, Christoph wrote:

                                    Hi Ichiroh,

                                    thanks for the update. It looks good to me. 
I'll run it through test

                                    system tonight and let you know if we see 
issues by tomorrow.

                Should

                                    you not hear back from me, consider it as 
reviewed and tested😊

                                    Thanks

                                    Christoph

                                        -----Original Message-----

                                        From: Ichiroh 
Takiguchi<taki...@linux.vnet.ibm.com>  <mailto:taki...@linux.vnet.ibm.com>

                                        Sent: Montag, 7. Oktober 2019 19:16

                                        To: Langer, 
Christoph<christoph.lan...@sap.com>  <mailto:christoph.lan...@sap.com>

                                        Cc:2d-dev@openjdk.java.net  
<mailto:2d-dev@openjdk.java.net>; Zeller,

        Arno<arno.zel...@sap.com>  <mailto:arno.zel...@sap.com>

                                        Subject: RE: [OpenJDK 2D-Dev] RFR: 
8221741 ClassCastException

                        happen

                                        when fontconfig.properties was used

                                        Hello Christoph.

                                        I appreciate your suggestion.

                                        JTreg testcase could throw 
ClassCastException instead of

                                        InvocationTargetException.

                                        JTreg results were in JDK-8221741

                                        
Bug:https://bugs.openjdk.java.net/browse/JDK-8221741

                                        Change:

                https://cr.openjdk.java.net/~itakiguchi/8221741/webrev.05/

                                        Could you review the fix ?

                                        Thanks,

                                        Ichiroh Takiguchi

                                        IBM Japan, Ltd.

                                        On 2019-10-07 22:53, Langer, Christoph 
wrote:

                                            Hi Ichiroh,

                                            this is great, thanks for doing 
this. We regularly see this and

                                            just

                                            stumbled over it the other day 
where the fontconfig of our test

                                            user

                                            was corrupted somehow.

                                            As for the test, I would reduce the 
amount of reflection a little

                                            bit.

                                            It should not be necessary to 
access SunFontManager via

                                            Class.forName,

                                            you already exported it to the test 
via the @modules statement.

                You

                                            can probably use this coding 
(please try as I didn't test it😊):

                                                        SunFontManager sfm = 
SunFontManager.getInstance();

                                                        Field 
defaultFontName_fid =

                                            
SunFontManager.class.getDeclaredField("defaultFontName");

                                                        
defaultFontName_fid.setAccessible(true);

                                                        defaultFontName_fid.set(sfm, 
"Dialog");

                                                        Method loadFonts_mid =

                                            
SunFontManager.class.getDeclaredMethod("loadFonts");

                                                        
loadFonts_mid.setAccessible(true);

                                                        
loadFonts_mid.invoke(sfm);

                                                        PhysicalFont 
physicalFont = sfm.getDefaultPhysicalFont();

                                                        
System.out.println(physicalFont);

                                            If you want, I can run your 
(updated) patch through our test

                                            system.

                                            Thanks

                                            Christoph

                                                -----Original Message-----

                                                From: 
2d-dev<2d-dev-boun...@openjdk.java.net>  
<mailto:2d-dev-boun...@openjdk.java.net>   On Behalf

        Of

                                                Ichiroh

                                                Takiguchi

                                                Sent: Montag, 7. Oktober 2019 
09:33

                                                To:2d-dev@openjdk.java.net  
<mailto:2d-dev@openjdk.java.net>

                                                Subject: [OpenJDK 2D-Dev] RFR: 
8221741 ClassCastException

                happen

                                        when

                                                fontconfig.properties was used

                                                Hello.

                                                Could you review the fix ?

                                                
Bug:https://bugs.openjdk.java.net/browse/JDK-8221741

                                                Change:

                        
https://cr.openjdk.java.net/~itakiguchi/8221741/webrev.04/

                                                JTreg testcase and results are 
including JDK-8221741 [1].

                                                
[1]https://bugs.openjdk.java.net/browse/JDK-8221741

                                                Thanks,

                                                Ichiroh Takiguchi

                                                IBM Japan, Ltd.


Reply via email to