RFR: 8286867: Update #getGlyphCode return a negative number
Kevin Rushforth
kcr at openjdk.org
Tue Jun 28 12:37:55 UTC 2022
On Fri, 13 May 2022 05:34:08 GMT, Tomator <duke at openjdk.org> wrote:
> When I used BlueJ, I found a problem with Chinese display. /javafx.graphics/com/sun/javafx/font/CompositeGlyphMapper.java#getGlyphCode may return a negative number when no font library is specified in Linux,and this could cause java.lang.ArrayIndexOutOfBoundsException error.So javafx.graphics/com/sun/prism/impl/GlyphCache.java#getCachedGlyph shou check the glyphCode.
> The crash demo like this:
> `import javafx.application.Application;
> import javafx.scene.Scene;
> import javafx.scene.control.Menu;
> import javafx.scene.control.MenuBar;
> import javafx.scene.control.MenuItem;
> import javafx.scene.layout.BorderPane;
> import javafx.stage.Stage;
>
> public class MenuExample extends Application {
> public static void main(String[] args) {
> launch(args);
> }
>
> @Override
> public void start(Stage primaryStage) throws Exception {
> BorderPane root = new BorderPane();
> Scene scene = new Scene(root,200,300);
> MenuBar menubar = new MenuBar();
> Menu FileMenu = new Menu("文本");
> MenuItem filemenu1=new MenuItem("新建");
> MenuItem filemenu2=new MenuItem("Save");
> MenuItem filemenu3=new MenuItem("Exit");
> Menu EditMenu=new Menu("Edit");
> MenuItem EditMenu1=new MenuItem("Cut");
> MenuItem EditMenu2=new MenuItem("Copy");
> MenuItem EditMenu3=new MenuItem("Paste");
> EditMenu.getItems().addAll(EditMenu1,EditMenu2,EditMenu3);
> root.setTop(menubar);
> FileMenu.getItems().addAll(filemenu1,filemenu2,filemenu3);
> menubar.getMenus().addAll(FileMenu,EditMenu);
> primaryStage.setScene(scene);
> primaryStage.setTitle("TEST");
> primaryStage.show();
>
> }
> } `
>
> the error:
> `java.lang.ArrayIndexOutOfBoundsException: Index -25 out of bounds for length 32
> at com.sun.prism.impl.GlyphCache.getCachedGlyph(GlyphCache.java:332)
> at com.sun.prism.impl.GlyphCache.render(GlyphCache.java:148)
> at com.sun.prism.impl.ps.BaseShaderGraphics.drawString(BaseShaderGraphics.java:2101)
> at com.sun.javafx.sg.prism.NGText.renderText(NGText.java:312)
> at com.sun.javafx.sg.prism.NGText.renderContent2D(NGText.java:270)
> at com.sun.javafx.sg.prism.NGShape.renderContent(NGShape.java:261)
> at com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:2072)
> at com.sun.javafx.sg.prism.NGNode.render(NGNode.java:1964)
> at com.sun.javafx.sg.prism.NGGroup.renderContent(NGGroup.java:270)
> at com.sun.javafx.sg.prism.NGRegion.renderContent(NGRegion.java:578)
> at com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:2072)
> at com.sun.javafx.sg.prism.NGNode.render(NGNode.java:1964)
> at com.sun.javafx.sg.prism.NGGroup.renderContent(NGGroup.java:270)
> at com.sun.javafx.sg.prism.NGRegion.renderContent(NGRegion.java:578)
> at com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:2072)
> at com.sun.javafx.sg.prism.NGNode.render(NGNode.java:1964)
> at com.sun.javafx.sg.prism.NGGroup.renderContent(NGGroup.java:270)
> at com.sun.javafx.sg.prism.NGRegion.renderContent(NGRegion.java:578)
> at com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:2072)
> at com.sun.javafx.sg.prism.NGNode.render(NGNode.java:1964)
> at com.sun.javafx.sg.prism.NGGroup.renderContent(NGGroup.java:270)
> at com.sun.javafx.sg.prism.NGRegion.renderContent(NGRegion.java:578)
> at com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:2072)
> at com.sun.javafx.sg.prism.NGNode.render(NGNode.java:1964)
> at com.sun.javafx.sg.prism.NGGroup.renderContent(NGGroup.java:270)
> at com.sun.javafx.sg.prism.NGRegion.renderContent(NGRegion.java:578)
> at com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:2072)
> at com.sun.javafx.sg.prism.NGNode.render(NGNode.java:1964)
> at com.sun.javafx.tk.quantum.ViewPainter.doPaint(ViewPainter.java:479)
> at com.sun.javafx.tk.quantum.ViewPainter.paintImpl(ViewPainter.java:328)
> at com.sun.javafx.tk.quantum.PresentingPainter.run(PresentingPainter.java:91)
> `
I left a question and style comment inline.
Can you provide an automated test case, or if that's not possible, a manual test case?
modules/javafx.graphics/src/main/java/com/sun/prism/impl/GlyphCache.java line 242:
> 240:
> 241: private GlyphData getCachedGlyph(int glyphCode, int subPixel) {
> 242: if (glyphCode < 0) {return null;}
Have you ensured that all callers are prepared to deal with a `null` return value?
Minor: Please format this according to code conventions:
if (glyphCode < 0) {
return null;
}
-------------
PR: https://git.openjdk.org/jfx/pull/795
More information about the openjfx-dev
mailing list