JDK-8252965 : [macos] Font.canDisplayUpTo returns wrong index for Indic text which causes crash later | OpenJDK Corretto 8.265.01.2
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: openjdk8u265
  • Priority: P4
  • Status: Closed
  • Resolution: External
  • OS: os_x
  • CPU: x86_64
  • Submitted: 2020-09-04
  • Updated: 2020-10-05
  • Resolved: 2020-10-05
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
openjdk8uResolved
Related Reports
Duplicate :  
Description
ADDITIONAL SYSTEM INFORMATION :
macOS 10.15.6 (also breaks on 10.14 and 10.13)
OpenJDK Corretto 8.265.01.2

A DESCRIPTION OF THE PROBLEM :
We have a JTable that displays rows of information. One column in the table has data in the language of the content associated with the row. Some characters in the text are not displayable by the UI font.  So we use java.awt.Font.caDisplayUpTo on the entries in this column. If any cannot be displayed, then we hide the column.
With a specific dataset with Malayalam text, the API return -1 (saying that it can be displayed with Lucida Grande font) while on Windows it return 0 (saying that it can't display any of the text with Tahoma font). On Linux it return -1 and displays correctly.

Later on, when trying to display the text in the JTable, an exception happens in:

libfontmanager.dylib
IndicRearrangementProcessor2::doRearrangementAction(LEGlyphStorage&, IndicRearrangementVerb, LEErrorCode&) 

Sometime, the callstack is slightly different or it can't determine it.

Here is a crash report from the sample code below:
https://drive.google.com/file/d/18-6TVQ591J_YgtaOP1-o3NFgPiGIhyfV/view?usp=sharing

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Install Scripture App Builder (https://software.sil.org/scriptureappbuilder/download)
Install Corretto JDK
Create a new project
Add book with Malayalam text (USFM markup with \h tag with Malayalam book name)

Here is a video showlng how to to reproduce the crash:
https://www.loom.com/share/8a93b968dee04bd79297b06ef68af9de

Here is the dataset that causes the crash:
https://drive.google.com/drive/folders/1hlq4_D3SG9BTY6B4-I0CbjT_YI4w3Ftc?usp=sharing



EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Either:
1 - Font.canDisplayTo should return 0 so that we know to not display the column of text (Like Windows)
2 - Display the text correctly (Like Linux)
ACTUAL -
App crashes when trying to display text that the system has said it could display.

---------- BEGIN SOURCE ----------
package org.sil;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.*;

public class Main {
    public static void main(String[] args) {
        Main app = new Main();
        app.buildAndDisplayGui();
    }

    private void buildAndDisplayGui() {
        JFrame frame = new JFrame("Test");
        buildContent(frame);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setVisible(true);
    }

    private void buildContent(JFrame frame) {
        JPanel panel = new JPanel();
        JTable table = new JTable();

        String[] columnNames = new String[2];
        columnNames[0] = "Book Id";
        columnNames[1] = "Book Name";

        DefaultTableModel model = new DefaultTableModel(columnNames, 2);
        table.setModel(model);

        // This works
        addRow(model, table.getFont(), "1", "Test");
        // This crashes
        addRow(model, table.getFont(), "2", "������������������������������������������������������������������������������������");
        updateRowHeights(table);

        panel.add(table);
        frame.getContentPane().add(panel);
    }

    private void addRow(DefaultTableModel model, Font font, String bookId, String bookName) {
        Object[] columns = new Object[2];

        columns[0] = bookId;
        if (font.canDisplayUpTo(bookName) < 0) {
            columns[1] = bookName;
        } else {
            columns[1] = "Fail";
        }

        model.addRow(columns);
    }

    private void updateRowHeights(JTable table)
    {
        try {
            for (int row = 0; row < table.getRowCount(); row++) {
                int rowHeight = table.getRowHeight();

                for (int column = 0; column < table.getColumnCount(); column++) {
                    Component comp = table.prepareRenderer(table.getCellRenderer(row, column), row, column);
                    rowHeight = Math.max(rowHeight, comp.getPreferredSize().height);
                }

                table.setRowHeight(row, rowHeight);
            }
        }
        catch(ClassCastException e) {
        }
    }

}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Use JDK 8u202 (we are nonprofit so can't use JDK 8u261)

FREQUENCY : always



Comments
Tracked in the Correto project by https://github.com/corretto/corretto-8/issues/268
05-10-2020

This looks like a Corretto-only problem. I've created the [Corretto issue 268](https://github.com/corretto/corretto-8/issues/268) to track it and will close this as "Won't fix".
05-10-2020

The crash is in the old ICU layout code which was replaced by HarfBuzz in jdk11. Oracle jdk8 uses t2k instead of freetype which might explain the differences between Corretto and Oracle JDK.
16-09-2020

Crashes with Corretto, but not Oracle JDK 8u (I tried 8u60->8u261) I didn't try the former but I can confirm no crash with the latter.
15-09-2020

Additional Information from Submitter: =========================== This is an issue with OpenJDK 8u265. I just tested again with the following release and the results. Oracle Java 8u261 : works Oracle Java 14.0.2 : works Amazon Corretto 8u265 : crashes Amazon Corretto 11.0.8.10.1 : works We are a nonprofit so (as far as I know) we can���t bundle Oracle Java 8u265 JRE with our Mac app. When searching for how to report bugs with OpenJDK, I found this article which states to report to bug report.java.com: https://stackoverflow.com/questions/29379425/where-to-report-issues-of-openjdk-when-youre-not-a-openjdk-developer
15-09-2020

Additional Information from Submitter: =========================== I noticed that the process of the Indic text looks garbled by the bug system. Here is a gist of the code that causes a crash with OpenJDK Corretto 8.265.01.2 https://gist.github.com/chrisvire/c27c725595b9da76859fbfe3a874ddbf This should not be closed as duplicated since the issue referenced is closed as not an issue. This is causing a crash!
14-09-2020

Additional Information from Submitter: =========================== This issue is marked as a duplicate of JDK-8223834 which is closed as not an issue. However, the Java app crashes when trying to display text when the java.awt.Font.canDisplayUpTo reports that it can display it (returns -1). In JDK-8223834, it states: "That is because Apple always implemented fall back support so if this font doesn't have the code points, they come from another font. So this is just an Apple behaviour." However the Java app crashes using OpenJDK (it doesn't crash with Oracle JDK) when it tries to display the text. The crash is in IndicRearrangementProcessor2. This issues should either not be closed
14-09-2020

Duplicates to JDK-8223834
09-09-2020