-
Bug
-
Resolution: Duplicate
-
P4
-
7
-
x86
-
windows_vista
Java Version: 1.7.0-b124
Platform: windows Vista
Problems:
In b124 promotion testing, there is a test called FontStyleTest failed by threw exceptions.
The exception threw when display font name "High Tower Text" with style isBold as below:
Test is PASS: Font Name: Harrington Font Style: isItalic
Test is PASS: Font Name: Harrington Font Style: isPlain
Test is PASS: Font Name: Harrington Font Style: isBold
Test is PASS: Font Name: Harrington Font Style: isItalic
Test is PASS: Font Name: High Tower Text Font Style: isPlain
FontStyleTest is: FAIL
Exception thrown
java.lang.NullPointerException
at sun.font.FileFontStrike.getCachedGlyphPtr(FileFontStrike.java:443)
at sun.font.FileFontStrike.getGlyphImagePtrs(FileFontStrike.java:390)
at sun.font.GlyphList.mapChars(GlyphList.java:272)
at sun.font.GlyphList.setFromString(GlyphList.java:244)
at sun.java2d.pipe.GlyphListPipe.drawString(GlyphListPipe.java:71)
at sun.java2d.pipe.ValidatePipe.drawString(ValidatePipe.java:165)
at sun.java2d.SunGraphics2D.drawString(SunGraphics2D.java:2807)
at FontStyleTest.drawStringWithFont(FontStyleTest.java:238)
at FontStyleTest.doTest(FontStyleTest.java:144)
at javasoft.clientsqe.tonga.AbstractTongaAutoTest.invokeTest(AbstractTongaAutoTest.java:65)
at javasoft.clientsqe.tonga.TTBuilder.main(TTBuilder.java:116)
since the font size is randomly generated, we don't know exactly size caused the exception.
Please find the original testcase in attachment section, and a modified standalone testcase as following, but I cannot reproduce the exceptions in windows vista with the test case, file a bug for record to trace this problem.
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Font;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GraphicsEnvironment;
import java.awt.Window;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
public class FontTest {
private String failMessage = null;
String[] fontFamilyNames = null;
private static final String FAIL = " getSyle() returns wrong value by ";
StringBuffer buf = new StringBuffer(256);
int fontStyles[] = { Font.PLAIN, Font.BOLD, Font.ITALIC };
String fStyle[] = { "isPlain", "isBold", "isItalic" };
BufferedImage base_image = null, target_image = null;
String fontName = "High Tower Text";
AffineTransform[] tranfms;
/** transforms do AffineTransform, scale, etc */
public void transforms() {
tranfms = new AffineTransform[3];
tranfms[0] = new AffineTransform();
tranfms[1] = new AffineTransform();
tranfms[1].setToScale(2f, 2f);
tranfms[2] = new AffineTransform();
tranfms[2].setToTranslation(20f, 20f);
}
public void doTest() {
GraphicsEnvironment ge = GraphicsEnvironment
.getLocalGraphicsEnvironment();
fontFamilyNames = ge.getAvailableFontFamilyNames();
Frame frame = new Frame("Font Style Test");
DrawFont dc = new DrawFont();
frame.add(dc);
frame.setLocation(20, 50);
frame.setSize(800, 600);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
((Window) we.getSource()).dispose();
System.out
.println("annotate TEST message=Test Aborted by the user.");
System.exit(0);
}
});
frame.setVisible(true);
try {
Thread.sleep(100);
} catch (Exception e) {
e.printStackTrace();
}
transforms();
for (int j = 0; j < tranfms.length; j++) {
for (int s = 8; s < 27; s++) {
try {
for (int style =0; style <fontStyles.length; style++) {
Font f = new Font(fontName, fontStyles[style],s);
String fontInfo = " Font Name: " + fontName + " Font Style: " + fStyle[style] + "\n ";
// derive a font with style we set
Font setFont = f.deriveFont(fontStyles[style], tranfms[j]);
Font getFont = f.deriveFont(f.getStyle(), tranfms[j]);
if (fontName == null || tranfms[j] == null
|| setFont == null || getFont == null) {
return;
}
if (setFont.getStyle() == style) {
dc.setFontParameters(getFont, fontName);
dc.repaint();
try {
Thread.sleep(10);
} catch (Exception e) {
e.printStackTrace();
failMessage = "Exception thrown when calling sleep()"
+ " after the repaint of the canvas ";
}
// draw String with font style
base_image = drawStringWithFont(setFont, "base");
target_image = drawStringWithFont(getFont, "target");
if ((checkFontStyle(getFont, style) == true)){
System.out.println(buf.append("Test is PASS: "
+ fontInfo));
} else {
}
} else {
buf.append(FAIL + fontInfo);
}
}
}
catch(Exception eex) {
eex.printStackTrace();
}
}
frame.dispose();
try {
Thread.sleep(100);
} catch (Exception e) {
e.printStackTrace();
}
failMessage = buf.toString();
}
}
/** main method */
public static void main(String argv[]) {
/** To construct an object */
FontTest aftest = new FontTest();
aftest.doTest();
}
/**
*
* @param f
* @param i
* @return
*/
public boolean checkFontStyle(Font f, int i) {
if (i == 0) {
return f.isPlain();
}
if (i == 1) {
return f.isBold();
}
if (i == 2) {
return f.isItalic();
} else {
System.out.println(" no style is found");
return false;
}
}
/**
* draw String with Font Style
*
* @param ft
* @param name
* @return
*/
private BufferedImage drawStringWithFont(Font ft, String name) {
BufferedImage img = new BufferedImage(500, 500,
BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = img.createGraphics();
g2d.setFont(ft);
g2d.setColor(Color.blue);
if (g2d != null) {
g2d.dispose();
}
return img;
}
}
class DrawFont extends Canvas {
/**
*
*/
private static final long serialVersionUID = 1L;
Font f = null;
String fontFamilyName = "";
public DrawFont() {
setSize(600, 400);
}
public void setFontParameters(Font font, String fontName) {
f = font;
fontFamilyName = fontName;
}
public void paint(Graphics g) {
if (f != null) {
Graphics2D g2d = (Graphics2D) g;
g2d.setFont(f);
g2d.setColor(Color.blue);
g2d.drawString(f.getFontName(), 150, 200);
}
}
}
Platform: windows Vista
Problems:
In b124 promotion testing, there is a test called FontStyleTest failed by threw exceptions.
The exception threw when display font name "High Tower Text" with style isBold as below:
Test is PASS: Font Name: Harrington Font Style: isItalic
Test is PASS: Font Name: Harrington Font Style: isPlain
Test is PASS: Font Name: Harrington Font Style: isBold
Test is PASS: Font Name: Harrington Font Style: isItalic
Test is PASS: Font Name: High Tower Text Font Style: isPlain
FontStyleTest is: FAIL
Exception thrown
java.lang.NullPointerException
at sun.font.FileFontStrike.getCachedGlyphPtr(FileFontStrike.java:443)
at sun.font.FileFontStrike.getGlyphImagePtrs(FileFontStrike.java:390)
at sun.font.GlyphList.mapChars(GlyphList.java:272)
at sun.font.GlyphList.setFromString(GlyphList.java:244)
at sun.java2d.pipe.GlyphListPipe.drawString(GlyphListPipe.java:71)
at sun.java2d.pipe.ValidatePipe.drawString(ValidatePipe.java:165)
at sun.java2d.SunGraphics2D.drawString(SunGraphics2D.java:2807)
at FontStyleTest.drawStringWithFont(FontStyleTest.java:238)
at FontStyleTest.doTest(FontStyleTest.java:144)
at javasoft.clientsqe.tonga.AbstractTongaAutoTest.invokeTest(AbstractTongaAutoTest.java:65)
at javasoft.clientsqe.tonga.TTBuilder.main(TTBuilder.java:116)
since the font size is randomly generated, we don't know exactly size caused the exception.
Please find the original testcase in attachment section, and a modified standalone testcase as following, but I cannot reproduce the exceptions in windows vista with the test case, file a bug for record to trace this problem.
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Font;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GraphicsEnvironment;
import java.awt.Window;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
public class FontTest {
private String failMessage = null;
String[] fontFamilyNames = null;
private static final String FAIL = " getSyle() returns wrong value by ";
StringBuffer buf = new StringBuffer(256);
int fontStyles[] = { Font.PLAIN, Font.BOLD, Font.ITALIC };
String fStyle[] = { "isPlain", "isBold", "isItalic" };
BufferedImage base_image = null, target_image = null;
String fontName = "High Tower Text";
AffineTransform[] tranfms;
/** transforms do AffineTransform, scale, etc */
public void transforms() {
tranfms = new AffineTransform[3];
tranfms[0] = new AffineTransform();
tranfms[1] = new AffineTransform();
tranfms[1].setToScale(2f, 2f);
tranfms[2] = new AffineTransform();
tranfms[2].setToTranslation(20f, 20f);
}
public void doTest() {
GraphicsEnvironment ge = GraphicsEnvironment
.getLocalGraphicsEnvironment();
fontFamilyNames = ge.getAvailableFontFamilyNames();
Frame frame = new Frame("Font Style Test");
DrawFont dc = new DrawFont();
frame.add(dc);
frame.setLocation(20, 50);
frame.setSize(800, 600);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
((Window) we.getSource()).dispose();
System.out
.println("annotate TEST message=Test Aborted by the user.");
System.exit(0);
}
});
frame.setVisible(true);
try {
Thread.sleep(100);
} catch (Exception e) {
e.printStackTrace();
}
transforms();
for (int j = 0; j < tranfms.length; j++) {
for (int s = 8; s < 27; s++) {
try {
for (int style =0; style <fontStyles.length; style++) {
Font f = new Font(fontName, fontStyles[style],s);
String fontInfo = " Font Name: " + fontName + " Font Style: " + fStyle[style] + "\n ";
// derive a font with style we set
Font setFont = f.deriveFont(fontStyles[style], tranfms[j]);
Font getFont = f.deriveFont(f.getStyle(), tranfms[j]);
if (fontName == null || tranfms[j] == null
|| setFont == null || getFont == null) {
return;
}
if (setFont.getStyle() == style) {
dc.setFontParameters(getFont, fontName);
dc.repaint();
try {
Thread.sleep(10);
} catch (Exception e) {
e.printStackTrace();
failMessage = "Exception thrown when calling sleep()"
+ " after the repaint of the canvas ";
}
// draw String with font style
base_image = drawStringWithFont(setFont, "base");
target_image = drawStringWithFont(getFont, "target");
if ((checkFontStyle(getFont, style) == true)){
System.out.println(buf.append("Test is PASS: "
+ fontInfo));
} else {
}
} else {
buf.append(FAIL + fontInfo);
}
}
}
catch(Exception eex) {
eex.printStackTrace();
}
}
frame.dispose();
try {
Thread.sleep(100);
} catch (Exception e) {
e.printStackTrace();
}
failMessage = buf.toString();
}
}
/** main method */
public static void main(String argv[]) {
/** To construct an object */
FontTest aftest = new FontTest();
aftest.doTest();
}
/**
*
* @param f
* @param i
* @return
*/
public boolean checkFontStyle(Font f, int i) {
if (i == 0) {
return f.isPlain();
}
if (i == 1) {
return f.isBold();
}
if (i == 2) {
return f.isItalic();
} else {
System.out.println(" no style is found");
return false;
}
}
/**
* draw String with Font Style
*
* @param ft
* @param name
* @return
*/
private BufferedImage drawStringWithFont(Font ft, String name) {
BufferedImage img = new BufferedImage(500, 500,
BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = img.createGraphics();
g2d.setFont(ft);
g2d.setColor(Color.blue);
if (g2d != null) {
g2d.dispose();
}
return img;
}
}
class DrawFont extends Canvas {
/**
*
*/
private static final long serialVersionUID = 1L;
Font f = null;
String fontFamilyName = "";
public DrawFont() {
setSize(600, 400);
}
public void setFontParameters(Font font, String fontName) {
f = font;
fontFamilyName = fontName;
}
public void paint(Graphics g) {
if (f != null) {
Graphics2D g2d = (Graphics2D) g;
g2d.setFont(f);
g2d.setColor(Color.blue);
g2d.drawString(f.getFontName(), 150, 200);
}
}
}
- duplicates
-
JDK-7007299 FileFontStrike appears not to be threadsafe?
-
- Closed
-