-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
1.4.1
-
x86
-
windows_nt
Name: jk109818 Date: 10/08/2002
FULL PRODUCT VERSION :
java version "1.4.1-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-beta-b14)
Java HotSpot(TM) Client VM (build 1.4.1-beta-b14, mixed mode)
AND
java version "1.4.1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-b21)
Java HotSpot(TM) Client VM (build 1.4.1-b21, mixed mode)
FULL OPERATING SYSTEM VERSION :
Windows NT 4.0 sp 5
A DESCRIPTION OF THE PROBLEM :
When setting some correct html documents for
javax.swing.JTextPane, they are not displayed and an audio
beep is emitted. Looking for the reason, I found, that
javax.swing.text.ChangedCharSetException is throwed outside
javax.swing.text.html.parser.DocumentParser.handleEmptyTag
(DocumentParser.java:169) and catched inside the setText()
method of JEditorPane. This happens even during the first
call of setText(), when no any initial charset should be
supposed. From the side, it looks as JTextPane is just not
able to display some correct documents.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
You just need a html file with the unacceptable charset.
Here is the beginning of the real html document. This
fragment is sufficient cause the mentioned problem:
<HTML>
<HEAD>
<TITLE>UniSTS</TITLE>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<meta name="keywords" content="NCBI, markers, genome,
genomic, map, maps, STS, STSs, epcr, electronic PCR, ePCR">
<meta name="description" content="A marker information
resources with links to mapping, GenBank and human genome.">
<link rel="stylesheet" href="NCBI.css">
</HEAD>
<BODY BGCOLOR="#FFFFFF" LINK="#0000FF" VLINK="#660099"
ALINK="#660099" background="IMG/bkgd.gif" TEXT="#000000">
</BODY>
With the provided source code, this will display the
exception stack trace. To make the stack trace visible, I
overrided the setText method, using exact your source code
of JEditorPane in the main part. To see the exception, the
component need not be displayed in GUI.
EXPECTED VERSUS ACTUAL BEHAVIOR :
If the swing component was created with a parameterless
constructor, the first call of setText must NOT report that
charset or something else have changed in an unacceptable
way. This should only happen if you try to append text to
an existing document. In general, just emitting an audio
beep without reporting what happened looks like bad
programming style.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
javax.swing.text.ChangedCharSetException
at javax.swing.text.html.parser.DocumentParser.handleEmptyTag
(DocumentParser.java:169)
at javax.swing.text.html.parser.Parser.startTag(Parser.java:372)
at javax.swing.text.html.parser.Parser.parseTag(Parser.java:1846)
at javax.swing.text.html.parser.Parser.parseContent(Parser.java:1881)
at javax.swing.text.html.parser.Parser.parse(Parser.java:2047)
at javax.swing.text.html.parser.DocumentParser.parse
(DocumentParser.java:106)
at javax.swing.text.html.parser.ParserDelegator.parse
(ParserDelegator.java:78)
at Sight.tools.xCreator.htmlFrame.stalkerParser.parse
(stalkerParser.java:25)
at javax.swing.text.html.HTMLEditorKit.read(HTMLEditorKit.java:230)
at Sight.tools.xCreator.htmlFrame.stalkerFrame.setText
(stalkerFrame.java:86)
at Sight.tools.xStalker.xStalkerSamplePanel.setSample
(xStalkerSamplePanel.java:106)
at Sight.tools.xStalker.frmSignatures.addHtmlResponse
(frmSignatures.java:257)
at Sight.tools.xCreator.frmSelectRobot.bStrategies_actionPerformed
(frmSelectRobot.java:196)
at Sight.tools.xCreator.frmSelectRobot$1.actionPerformed
(frmSelectRobot.java:49)
at javax.swing.AbstractButton.fireActionPerformed
(AbstractButton.java:1764)
at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed
(AbstractButton.java:1817)
at javax.swing.DefaultButtonModel.fireActionPerformed
(DefaultButtonModel.java:419)
at javax.swing.DefaultButtonModel.setPressed
(DefaultButtonModel.java:257)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased
(BasicButtonListener.java:245)
at java.awt.Component.processMouseEvent(Component.java:5093)
at java.awt.Component.processEvent(Component.java:4890)
at java.awt.Container.processEvent(Container.java:1566)
at java.awt.Component.dispatchEventImpl(Component.java:3598)
at java.awt.Container.dispatchEventImpl(Container.java:1623)
at java.awt.Component.dispatchEvent(Component.java:3439)
at java.awt.LightweightDispatcher.retargetMouseEvent
(Container.java:3450)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3165)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3095)
at java.awt.Container.dispatchEventImpl(Container.java:1609)
at java.awt.Window.dispatchEventImpl(Window.java:1585)
at java.awt.Component.dispatchEvent(Component.java:3439)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:450)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy
(EventDispatchThread.java:197)
at java.awt.EventDispatchThread.pumpEventsForHierarchy
(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.io.*;
import javax.swing.text.*;
public class HtmlBug extends javax.swing.JTextPane {
// There is no need to display the component to see the exception.
public static void main(String[] args) {
try {
HtmlBug bug = new HtmlBug();
bug.setContentType("text/html");
StringBuffer b = new StringBuffer();
BufferedReader reader= new BufferedReader(
new FileReader("E:\\JBuilder\\Experiments\\Experiments\\HtmlBug.html"));
String s;
while ( (s=reader.readLine() ) != null) {
b.append(s);
b.append("\n");
}
bug.setText(b.toString());
} catch (Exception exc)
{ exc.printStackTrace(); };
}
/** Copied from JEditorPane. */
public void setText(String t) {
try {
Document doc = getDocument();
doc.remove(0, doc.getLength());
if (t == null || t.equals("")) {
return;
}
Reader r = new StringReader(t);
EditorKit kit = getEditorKit();
kit.read(r, doc, 0);
} catch (Exception ex) {
// Print exception instead of audio beep:
ex.printStackTrace();
}
}
}
---------- END SOURCE ----------
CUSTOMER WORKAROUND :
The bug can be eliminated by providing the alternative html
parser with the following parse method:
public void parse(Reader r, HTMLEditorKit.ParserCallback
cb, boolean ignoreCharSet)
throws IOException
{
real.parse(r, cb, true);
};
(Review ID: 164914)
======================================================================
- duplicates
-
JDK-4625388 JEditorPane read method does not work with Changed Char set and doc w/o url
-
- Resolved
-