Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8328953

JEditorPane.read throws ChangedCharSetException

XMLWordPrintable

    • b124
    • 9
    • b17

        JEditorPane.read(InputStream in, Object desc) throws ChangedCharSetException when you load an HTML file which declares encoding using <meta> tag:

        <meta http-equiv="Content-Type" content="text/html; charset=windows-1251">

        Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: javax.swing.text.ChangedCharSetException
                at EditorPaneCharset.<init>(EditorPaneCharset.java:37)
                <13 internal lines>
        Caused by: javax.swing.text.ChangedCharSetException
                at java.desktop/javax.swing.text.html.parser.DocumentParser.handleEmptyTag(DocumentParser.java:202)
                at java.desktop/javax.swing.text.html.parser.Parser.startTag(Parser.java:504)
                at java.desktop/javax.swing.text.html.parser.Parser.parseTag(Parser.java:2054)
                at java.desktop/javax.swing.text.html.parser.Parser.parseContent(Parser.java:2195)
                at java.desktop/javax.swing.text.html.parser.Parser.parse(Parser.java:2372)
                at java.desktop/javax.swing.text.html.parser.DocumentParser.parse(DocumentParser.java:135)
                at java.desktop/javax.swing.text.html.parser.ParserDelegator.parse(ParserDelegator.java:114)
                at java.desktop/javax.swing.text.html.HTMLEditorKit.read(HTMLEditorKit.java:264)
                at java.desktop/javax.swing.JEditorPane.read(JEditorPane.java:621)
                at java.desktop/javax.swing.JEditorPane.read(JEditorPane.java:591)
                at EditorPaneCharset.<init>(EditorPaneCharset.java:31)
                ... 13 more

        Java 8 does not throw ChangedCharSetException, Java 11 and later do.

        Reported on behalf of rjolly: https://github.com/openjdk/jdk/pull/17567
        https://mail.openjdk.org/pipermail/discuss/2024-March/006340.html
        https://mail.openjdk.org/pipermail/client-libs-dev/2024-March/018311.html

        To reproduce run the attached EditorPaneCharset.java:
            java EditorPaneCharset.java

        For Java 8, compile the file first:
            javac EditorPaneCharset.java
            java EditorPaneCharset

              aivanov Alexey Ivanov
              aivanov Alexey Ivanov
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: