Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 6699843
Votes 0
Synopsis IllegalArgumentException found when using Graphics.drawString( "", 0, 0 )
Category java:classes_2d
Reported Against
Release Fixed 7(b28)
State 10-Fix Delivered, bug
Priority: 4-Low
Related Bugs 6478336
Submit Date 09-MAY-2008
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 :
 customer  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 ----------
Posted Date : 2008-05-09 16:14:38.0
Work Around
N/A
Evaluation
Need to check for the empty string before calling the TextLayout constructor.
Posted Date : 2008-05-13 18:27:06.0
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang