JDK-5059509 : REGRESSION: Font.decode() doesn't recognize PLAIN style
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 5.0
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2004-06-08
  • Updated: 2017-05-16
  • Resolved: 2004-06-21
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
5.0 b57Fixed
Description

Name: pr15447			Date: 06/07/2004


FULL PRODUCT VERSION :
java version "1.5.0-beta2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta2-b51)
Java HotSpot(TM) Client VM (build 1.5.0-beta2-b51, mixed mode, sharing)

A DESCRIPTION OF THE PROBLEM :
This code:

  System.out.println(Font.decode("monospaced-plain-14"));

yields this output:

  java.awt.Font[family=Dialog,name=monospaced-plain,style=plain,size=14]


The problem is with these lines from the decode() method:

	    if (styleName.equals("bolditalic")) {
		fontStyle = Font.BOLD | Font.ITALIC;
	    } else if (styleName.equals("italic")) {
		fontStyle = Font.ITALIC;
	    } else if (styleName.equals("bold")) {
		fontStyle = Font.BOLD;
	    } else {
		/* this string isn't any of the expected styles, so
		 * assume its part of the font name
		 */
		styleIndex = sizeIndex;
		if (str.charAt(styleIndex-1) == sepChar) {
		    styleIndex--;
		}
	    }

If no style is specified, it defaults to plain, but if "plain" is specified,
it's treated as part of the family name.

REGRESSION.  Last worked in version tiger-beta1


REPRODUCIBILITY :
This bug can be reproduced always.

CUSTOMER SUBMITTED WORKAROUND :
Instead, e.g., of "monospaced-plain-14", use "monospaced-14" and let the style
default to "plain".

Release Regression From : 1.4.2
The above release value was the last known release where this 
bug was known to work. Since then there has been a regression.

(Incident Review ID: 275520) 
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: tiger-rc FIXED IN: tiger-rc INTEGRATED IN: tiger-b57 tiger-rc
25-06-2004

SUGGESTED FIX --- Font.java Mon Jun 7 17:32:23 2004 *************** *** 1155,1163 **** * <li><em>fontname style</em> * <li><em>fontname</em> * </ul> ! * in which <i>style</i> is one of the three * case-insensitive strings: ! * <code>"BOLD"</code>, <code>"BOLDITALIC"</code>, or * <code>"ITALIC"</code>, and pointsize is a positive decimal integer * representation of the point size. * For example, if you want a font that is Arial, bold, with --- 1155,1163 ---- * <li><em>fontname style</em> * <li><em>fontname</em> * </ul> ! * in which <i>style</i> is one of the four * case-insensitive strings: ! * <code>"PLAIN"</code>, <code>"BOLD"</code>, <code>"BOLDITALIC"</code>, or * <code>"ITALIC"</code>, and pointsize is a positive decimal integer * representation of the point size. * For example, if you want a font that is Arial, bold, with *************** *** 1255,1260 **** --- 1255,1262 ---- fontStyle = Font.ITALIC; } else if (styleName.equals("bold")) { fontStyle = Font.BOLD; + } else if (styleName.equals("plain")) { + fontStyle = Font.PLAIN; } else { /* this string isn't any of the expected styles, so * assume its part of the font name ###@###.### 2004-06-07 ============================
07-06-2004

EVALUATION Font.decode() is implementing the spec to the letter, but the spec really should include plain as an explicitly allowable string. The particularly compelling reason for doing that is that this syntax was historically accepted, even if most people tended not to explicitly specify the "plain" style. At this point it would appear that both a spec relaxation (to allow plain) and a code update to match on it, are needed. ###@###.### 2004-06-07 ============================
07-06-2004

WORK AROUND Instead, e.g., of "monospaced-plain-14", use "monospaced-14" and let the style default to "plain". ###@###.### 2004-06-07 ==========================
07-06-2004