United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-6561485 : setting strikethrough on text throws illegalargumentexception

Details
Type:
Bug
Submit Date:
2007-05-24
Status:
Closed
Updated Date:
2010-04-04
Project Name:
JDK
Resolved Date:
2007-05-24
Component:
client-libs
OS:
windows_xp
Sub-Component:
2d
CPU:
x86
Priority:
P4
Resolution:
Duplicate
Affected Versions:
6
Fixed Versions:

Related Reports
Duplicate:

Sub Tasks

Description
FULL PRODUCT VERSION :
jdk1.5.0_06 built applet running with jre 1.6.0 update 1

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

A DESCRIPTION OF THE PROBLEM :
setting strikethrough on text causes an IllegalArgumentException to be thrown in,
java.lang.IllegalArgumentException: Zero length string passed to TextLayout constructor.
	at java.awt.font.TextLayout.<init>(Unknown Source)
	at sun.font.FontDesignMetrics.charsWidth(Unknown Source)

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Use my test case applet and clcik the button to turn on the strikethough on the text of the form.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
strikethrough to work
ACTUAL -
exception thrown and screen not being repainted properly

ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "AWT-EventQueue-1" java.lang.IllegalArgumentException: Zero length string passed to TextLayout constructor.
	at java.awt.font.TextLayout.<init>(Unknown Source)
	at sun.font.FontDesignMetrics.charsWidth(Unknown Source)
	at javax.swing.text.Utilities.getTabbedTextWidth(Unknown Source)
	at javax.swing.text.Utilities.getTabbedTextWidth(Unknown Source)
	at javax.swing.text.PlainView.getLineWidth(Unknown Source)
	at javax.swing.text.PlainView.calculateLongestLine(Unknown Source)
	at javax.swing.text.PlainView.updateMetrics(Unknown Source)
	at javax.swing.text.PlainView.setSize(Unknown Source)
	at javax.swing.plaf.basic.BasicTextUI$RootView.setSize(Unknown Source)
	at javax.swing.plaf.basic.BasicTextUI$RootView.paint(Unknown Source)
	at javax.swing.plaf.basic.BasicTextUI.paintSafely(Unknown Source)
	at javax.swing.plaf.basic.BasicTextUI.paint(Unknown Source)
	at javax.swing.plaf.basic.BasicTextUI.update(Unknown Source)
	at javax.swing.JComponent.paintComponent(Unknown Source)
	at javax.swing.JComponent.paint(Unknown Source)
	at javax.swing.JComponent.paintChildren(Unknown Source)
	at javax.swing.JComponent.paint(Unknown Source)
	at javax.swing.JComponent.paintToOffscreen(Unknown Source)
	at javax.swing.BufferStrategyPaintManager.paint(Unknown Source)
	at javax.swing.RepaintManager.paint(Unknown Source)
	at javax.swing.JComponent._paintImmediately(Unknown Source)
	at javax.swing.JComponent.paintImmediately(Unknown Source)
	at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
	at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
	at javax.swing.RepaintManager.seqPaintDirtyRegions(Unknown Source)
	at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)
	at java.awt.event.InvocationEvent.dispatch(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
public class JStrikeThroughTestApplet extends JApplet implements ActionListener
{

	private javax.swing.JPanel jContentPane = null;

	private javax.swing.JTextField jTextField = null;
	private javax.swing.JButton jButton = null;
	private javax.swing.JLabel jLabel = null;
	
	private int SET_STRIKETHROUGH_ON  = 0;
	private int SET_STRIKETHROUGH_OFF = 1;
	
	private String [] buttonText = {"SetStrikeThough", "RemoveStrikeThrough"};

	/**
	 * @throws java.awt.HeadlessException
	 */
	public JStrikeThroughTestApplet() throws HeadlessException {
		super();
		// TODO Auto-generated constructor stub
		init();
	}

	public static void main(String[] args) {
	}
	/**
	 * This method initializes this
	 *
	 * @return void
	 */
	public void init() {
		this.setSize(300, 200);
		this.setContentPane(getJContentPane());
	}
	/**
	 * This method initializes jContentPane
	 *
	 * @return javax.swing.JPanel
	 */
	private javax.swing.JPanel getJContentPane() {
		if (jContentPane == null) {
			jContentPane = new javax.swing.JPanel();
			jContentPane.setLayout(null);
			jContentPane.add(getJTextField(), null);
			jContentPane.add(getJButton(), null);
			jContentPane.add(getJLabel(), null);
		}
		return jContentPane;
	}
	/**
	 * This method initializes jTextField
	 *
	 * @return javax.swing.JTextField
	 */
	private javax.swing.JTextField getJTextField() {
		if(jTextField == null) {
			jTextField = new javax.swing.JTextField();
			jTextField.setBounds(22, 47, 256, 20);
			jTextField.setText("TextField Text");
		}
		return jTextField;
	}
	/**
	 * This method initializes jButton
	 *
	 * @return javax.swing.JButton
	 */
	private javax.swing.JButton getJButton()
	{
		if(jButton == null)
		{
			jButton = new javax.swing.JButton();
			jButton.setBounds(23, 86, 253, 25);
			jButton.setText(buttonText[SET_STRIKETHROUGH_ON]);
			jButton.addActionListener(this);
			jButton.setActionCommand(buttonText[SET_STRIKETHROUGH_ON]);
		}
		return jButton;
	}
	/**
	 * This method initializes jLabel
	 *
	 * @return javax.swing.JLabel
	 */
	private javax.swing.JLabel getJLabel() {
		if(jLabel == null) {
			jLabel = new javax.swing.JLabel();
			jLabel.setBounds(22, 18, 256, 20);
			jLabel.setText("Label Text");
		}
		return jLabel;
	}

	/* (non-Javadoc)
	 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
	 */
	public void actionPerformed(ActionEvent e)
	{
		String action = e.getActionCommand();
		
		if(action.equals(buttonText[SET_STRIKETHROUGH_ON]))
		{
			jButton.setText(buttonText[SET_STRIKETHROUGH_OFF]);
			jButton.setActionCommand(buttonText[SET_STRIKETHROUGH_OFF]);
			
			updateFonts(SET_STRIKETHROUGH_ON);
			
		}
		else if(action.equals(buttonText[SET_STRIKETHROUGH_OFF]))
		{
			jButton.setText(buttonText[SET_STRIKETHROUGH_ON]);
			jButton.setActionCommand(buttonText[SET_STRIKETHROUGH_ON]);
			
			updateFonts(SET_STRIKETHROUGH_OFF);
			
		}
	}
	
	protected void updateFonts(int StrikeThroughState)
	{
		//label
		Font font  = getJLabel().getFont();
		
		Map Attribs = font.getAttributes();
		
		Attribs.put(TextAttribute.STRIKETHROUGH, StrikeThroughState == SET_STRIKETHROUGH_ON ? Boolean.TRUE : Boolean.FALSE);
		
		getJLabel().setFont(new Font(Attribs));
		
		//textfield
		
		font  = getJTextField().getFont();
		
		Attribs = font.getAttributes();

		Attribs.put(TextAttribute.STRIKETHROUGH, StrikeThroughState == SET_STRIKETHROUGH_ON ? Boolean.TRUE : Boolean.FALSE);

		getJTextField().setFont(new Font(Attribs));
		
		//button
		
		font  = getJButton().getFont();
		
		Attribs = font.getAttributes();

		Attribs.put(TextAttribute.STRIKETHROUGH, StrikeThroughState == SET_STRIKETHROUGH_ON ? Boolean.TRUE : Boolean.FALSE);

		getJButton().setFont(new Font(Attribs));
		
		/////////////////////////////////////////////////
		getJContentPane().repaint();
		
	}
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
none as it is a show stopper.

                                    

Comments
EVALUATION

Dup of 6478336, fixed in JDK 6u2
                                     
2007-05-24



Hardware and Software, Engineered to Work Together