-
Bug
-
Resolution: Unresolved
-
P4
-
None
-
6u19
-
x86
-
windows_xp
FULL PRODUCT VERSION :
java version "1.6.0_19"
Java(TM) SE Runtime Environment (build 1.6.0_19-b04)
Java HotSpot(TM) Client VM (build 16.2-b04, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
Microsoft Windows XP Professional Service Pack 3
A DESCRIPTION OF THE PROBLEM :
If you render an HTML form with a submit button inside a JLabel and do not close the <form> tag properly, a ClassCastException is thrown, when the user hits the submit button.
The example form looks as follows:
<html>
<form method="POST" action="http://example.com/">
<input type="text" name="foo" />"
<input type="submit" name="bar" value="submit" />
</html>
The closing </form> tag is missing.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Insert the html form into a JLabel.
2. Hit the submit button.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
No exception should be thrown and/or no form should be displayed.
ACTUAL -
A ClassCastException is thrown.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: javax.swing.JLabel cannot be cast to javax.swing.JEditorPane
at javax.swing.text.html.FormView.submitData(FormView.java:409)
at javax.swing.text.html.FormView.actionPerformed(FormView.java:356)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6263)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3255)
at java.awt.Component.processEvent(Component.java:6028)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4630)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2475)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.Dimension;
import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
public class MyTestFrame extends JFrame {
public MyTestFrame() {
JLabel lbl = new JLabel();
lbl.updateUI();
lbl.setText("<html><form method=\"POST\" action=\"http://blah.com/\">"
+ "<input type=\"text\" name=\"foo\" />"
+ "<input type=\"submit\" name=\"bar\" value=\"submit\" />"
+ "</html>");
this.setSize(new Dimension(100, 100));
this.setLayout(new FlowLayout());
this.add(lbl);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new MyTestFrame().setVisible(true);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
If no HTML code should be displayed:
Disable the rendering of HTML code:
myLabel.putClientProperty("html.disable", Boolean.TRUE);
If HTML code should be displayed and there is no user input involved:
Use proper HTML syntax.
If HTML code should be displayed and there is user input involved, that should not be part displayed as HTML:
Escape the inputs using some util class:
myLabel.setText(someHtmlString + Util.escapeXml(userinput); + someHtmlString2);
java version "1.6.0_19"
Java(TM) SE Runtime Environment (build 1.6.0_19-b04)
Java HotSpot(TM) Client VM (build 16.2-b04, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
Microsoft Windows XP Professional Service Pack 3
A DESCRIPTION OF THE PROBLEM :
If you render an HTML form with a submit button inside a JLabel and do not close the <form> tag properly, a ClassCastException is thrown, when the user hits the submit button.
The example form looks as follows:
<html>
<form method="POST" action="http://example.com/">
<input type="text" name="foo" />"
<input type="submit" name="bar" value="submit" />
</html>
The closing </form> tag is missing.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Insert the html form into a JLabel.
2. Hit the submit button.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
No exception should be thrown and/or no form should be displayed.
ACTUAL -
A ClassCastException is thrown.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: javax.swing.JLabel cannot be cast to javax.swing.JEditorPane
at javax.swing.text.html.FormView.submitData(FormView.java:409)
at javax.swing.text.html.FormView.actionPerformed(FormView.java:356)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6263)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3255)
at java.awt.Component.processEvent(Component.java:6028)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4630)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2475)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.Dimension;
import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
public class MyTestFrame extends JFrame {
public MyTestFrame() {
JLabel lbl = new JLabel();
lbl.updateUI();
lbl.setText("<html><form method=\"POST\" action=\"http://blah.com/\">"
+ "<input type=\"text\" name=\"foo\" />"
+ "<input type=\"submit\" name=\"bar\" value=\"submit\" />"
+ "</html>");
this.setSize(new Dimension(100, 100));
this.setLayout(new FlowLayout());
this.add(lbl);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new MyTestFrame().setVisible(true);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
If no HTML code should be displayed:
Disable the rendering of HTML code:
myLabel.putClientProperty("html.disable", Boolean.TRUE);
If HTML code should be displayed and there is no user input involved:
Use proper HTML syntax.
If HTML code should be displayed and there is user input involved, that should not be part displayed as HTML:
Escape the inputs using some util class:
myLabel.setText(someHtmlString + Util.escapeXml(userinput); + someHtmlString2);