ADDITIONAL SYSTEM INFORMATION :
macOS High Sierra 10.13.4
A DESCRIPTION OF THE PROBLEM :
FontMetrics.stringWidth causes a null pointer exception.
Have tried with the following versions
1.8.0_161 OK
10.0.1 OK
1.8.0_162 CRASH
1.8.0_172 CRASH
The crash was introduced in 1.8.0_162
Stack Trace:
Exception in thread "main" java.lang.NullPointerException
at sun.font.PhysicalStrike.getGlyphPoint(PhysicalStrike.java:138)
at sun.font.SunLayoutEngine.nativeLayout(Native Method)
at sun.font.SunLayoutEngine.layout(SunLayoutEngine.java:158)
at sun.font.GlyphLayout$EngineRecord.layout(GlyphLayout.java:685)
at sun.font.GlyphLayout.layout(GlyphLayout.java:466)
at sun.font.ExtendedTextSourceLabel.createGV(ExtendedTextSourceLabel.java:329)
at sun.font.ExtendedTextSourceLabel.getGV(ExtendedTextSourceLabel.java:315)
at sun.font.ExtendedTextSourceLabel.createLogicalBounds(ExtendedTextSourceLabel.java:225)
at sun.font.ExtendedTextSourceLabel.getAdvance(ExtendedTextSourceLabel.java:134)
at java.awt.font.TextLine.init(TextLine.java:281)
at java.awt.font.TextLine.<init>(TextLine.java:129)
at java.awt.font.TextLine.fastCreateTextLine(TextLine.java:983)
at java.awt.font.TextLayout.fastInit(TextLayout.java:612)
at java.awt.font.TextLayout.<init>(TextLayout.java:393)
at sun.font.FontDesignMetrics.stringWidth(FontDesignMetrics.java:478)
at seo.spider.serps.TestMe.getFontMetricsPixelWidth(TestMe.java:25)
at seo.spider.serps.TestMe.main(TestMe.java:16)
REGRESSION : Last worked in version 8u161
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the supplied source code and you will experience the crash.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Shouldn't crash with a NPE in
ACTUAL -
Exception in thread "main" java.lang.NullPointerException
at sun.font.PhysicalStrike.getGlyphPoint(PhysicalStrike.java:138)
at sun.font.SunLayoutEngine.nativeLayout(Native Method)
at sun.font.SunLayoutEngine.layout(SunLayoutEngine.java:158)
at sun.font.GlyphLayout$EngineRecord.layout(GlyphLayout.java:685)
at sun.font.GlyphLayout.layout(GlyphLayout.java:466)
at sun.font.ExtendedTextSourceLabel.createGV(ExtendedTextSourceLabel.java:329)
at sun.font.ExtendedTextSourceLabel.getGV(ExtendedTextSourceLabel.java:315)
at sun.font.ExtendedTextSourceLabel.createLogicalBounds(ExtendedTextSourceLabel.java:225)
at sun.font.ExtendedTextSourceLabel.getAdvance(ExtendedTextSourceLabel.java:134)
at java.awt.font.TextLine.init(TextLine.java:281)
at java.awt.font.TextLine.<init>(TextLine.java:129)
at java.awt.font.TextLine.fastCreateTextLine(TextLine.java:983)
at java.awt.font.TextLayout.fastInit(TextLayout.java:612)
at java.awt.font.TextLayout.<init>(TextLayout.java:393)
at sun.font.FontDesignMetrics.stringWidth(FontDesignMetrics.java:478)
at seo.spider.serps.TestMe.getFontMetricsPixelWidth(TestMe.java:25)
at seo.spider.serps.TestMe.main(TestMe.java:16)
---------- BEGIN SOURCE ----------
import java.awt.Canvas;
import java.awt.Font;
import java.awt.FontMetrics;
public class TestMe
{
private static final Canvas mCanvas = new Canvas();
private static final String ARIAL_FONT_NAME = "ArialUnicodeMS";
public static void main(
String[] args)
{
System.out.println(System.getProperty("java.version"));
int width = getFontMetricsPixelWidth("ïçæ����ç ��ç ��ê�� êìï��ï ç����ùïçê ç��ê����������ì��é ����", 14);
System.out.println("width " + width);
}
private static int getFontMetricsPixelWidth(
final String str,
int fontSize)
{
final FontMetrics fm = mCanvas.getFontMetrics(new Font(ARIAL_FONT_NAME, Font.PLAIN, fontSize));
return fm.stringWidth(str);
}
}
---------- END SOURCE ----------
FREQUENCY : always