JDK-4257064 : Source for java.awt.FontMetrics does not coorespond to binary (cf. 54216)
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.2.0
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • OS: generic
  • CPU: generic
  • Submitted: 1999-07-26
  • Updated: 1999-08-31
  • Resolved: 1999-08-31
Related Reports
Relates :  
Description

Name: wl91122			Date: 07/26/99


<pre>
Although technically not a bug, this problem pertains to JDKs
1.1.5 and 1.2, probably all JDKs between and possibly others.

The source code for the java.awt.FontMetrics class does not
coorespond to the binary code.  This means that the source
distributed with the JDK is not the source that was used to
build it.

Specifically, look at the src\java\awt\FontMetrics.java file
at the methods
    public int stringWidth(String str)
    public int charsWidth(char data[], int off, int len)

The segment of FontMetrics.java with these two methods is
as follows:

    /**
     * Returns the total advance width for showing the specified 
     * <code>String</code> in this <code>Font</code>. The advance width is
     * the amount by which the current point is moved from one character
     * to the next in a line of text.
     * @param str the <code>String</code> to be measured
     * @return    the advance width of the specified <code>String</code>
     *                  in the <code>Font</code> described by this
     *			<code>FontMetrics</code>.
     * @see       #bytesWidth(byte[], int, int)
     * @see       #charsWidth(char[], int, int)
     */
    public int stringWidth(String str) {
	int len = str.length();
	char data[] = new char[len];
	str.getChars(0, len, data, 0);
	return charsWidth(data, 0, len);
    }

    /**
     * Returns the total advance width for showing the specified array
     * of characters in this <code>Font</code>.  The advance width is the
     * amount by which the current point is moved from one character to
     * the next in a line of text.
     * @param data the array of characters to be measured
     * @param off the start offset of the characters in the array
     * @param len the number of characters to be measured from the array
     * @return    the advance width of the subarray of the specified
     *               <code>char</code> array in the font described by
     *               this <code>FontMetrics</code> object.
     * @see       #charWidth(int)
     * @see       #charWidth(char)
     * @see       #bytesWidth(byte[], int, int)
     * @see       #stringWidth(String)
     */
    public int charsWidth(char data[], int off, int len) {
	return stringWidth(new String(data, off, len));
    }

Notice that stringWidth unconditionally calls charsWidth and
that charsWidth unconditionally calls stringWidth.  Can you
say infinite mutual recursion?  Since both APIs work, the
binary code must not be implementing the above source.

It would be good to have the actual source of FontMetrics.
</pre>
(Review ID: 53783) 
======================================================================

Comments
WORK AROUND Name: wl91122 Date: 07/26/99 Not applicable ======================================================================
11-06-2004

EVALUATION The actual source used is in the subclasses of FontMetrics, where the methods stringWidth and charsWidth are overridden: src/solaris/classes/sun/awt/motif/X11FontMetrics.java src/win32/classes/sun/awt/windows/WFontMetrics.java mike.bronson@eng 1999-08-30
30-08-1999