United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6699843 IllegalArgumentException found when using Graphics.drawString( "", 0, 0 )
JDK-6699843 : IllegalArgumentException found when using Graphics.drawString( "", 0, 0 )

Details
Type:
Bug
Submit Date:
2008-05-09
Status:
Closed
Updated Date:
2011-03-08
Project Name:
JDK
Resolved Date:
2011-03-08
Component:
client-libs
OS:
windows_xp
Sub-Component:
2d
CPU:
x86
Priority:
P4
Resolution:
Fixed
Affected Versions:
6
Fixed Versions:

Related Reports
Relates:

Sub Tasks

Description
FULL PRODUCT VERSION :
java version "1.6.0_02"
Java(TM) SE Runtime Environment (build 1.6.0_02-b06)
Java HotSpot(TM) Client VM (build 1.6.0_02-b06, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
Running the attached code causes the attached IllegalArgumentException.

When the following line is removed, the exception is not thrown anymore.
    map.put( TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_LOW_ONE_PIXEL );

This seems to be related to Bug #6478336 which was correctly fixed in 6u2(b01).

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the attached code with JRE 1.6.0_02.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Do nothing. Drawing an empty string should not do anything.
ACTUAL -
The code throws the attached IllegalArgumentException.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "main" java.lang.IllegalArgumentException: Zero length string passed to TextLayout constructor.
	at java.awt.font.TextLayout.<init>(Unknown Source)
	at sun.java2d.SunGraphics2D.drawString(Unknown Source)
	at TestClass.main(TestClass.java:21)


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
public class TestClass {

  public static void main( String args[] ) {
    BufferedImage bi = new BufferedImage( 1, 1, BufferedImage.TYPE_INT_RGB );
    Graphics g = bi.getGraphics();

    Font f = new Font( "Dialog", Font.PLAIN, 12 );
    Map map = new HashMap();
    map.put( TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_LOW_ONE_PIXEL );
    f = f.deriveFont( map );
    g.setFont( f );
    g.drawString( "", 0, 0 );
  }

}

---------- END SOURCE ----------

                                    

Comments
EVALUATION

Need to check for the empty string before calling the TextLayout constructor.
                                     
2008-05-13



Hardware and Software, Engineered to Work Together