You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by "Alex Lumpov (Issue Comment Edited) (JIRA)" <ji...@apache.org> on 2011/11/24 18:23:39 UTC

[jira] [Issue Comment Edited] (TAP5-1741) Parsing template which contains Chinese (Maybe other double bytes) words throws MalformedByteSequenceException: Invalid byte 3 of 3-byte UTF-8 sequence.

    [ https://issues.apache.org/jira/browse/TAP5-1741?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13156833#comment-13156833 ] 

Alex Lumpov edited comment on TAP5-1741 at 11/24/11 5:21 PM:
-------------------------------------------------------------

I have the same problem.
Template has russian letters. My template ecnoding is UTF-8. But my default system encoding is Cp1251.
If tomcat starts with -Dfile.encoding=UTF-8 everything is ok.
But if tomcat starts without this option I has exception: Invalid byte 2 of 2-byte UTF-8 sequence.

new method in 5.3 XMLTokenStream.openStream() has:
337: InputStreamReader rawReader = new InputStreamReader(rawStream); // used default charset
341: PrintWriter writer = new PrintWriter(bos);  // used default charset

This means that the byte stream is converted from the system encoding to UTF-8 and then back. During this transformation a number of characters are wasted. In my case the solution would be the following:
337: InputStreamReader rawReader = new InputStreamReader(rawStream, "UTF-8"); // used UTF-8 charset
341: PrintWriter writer = new PrintWriter(new OutputStreamWriter(bos, "UTF-8"));  // used UTF-8 charset

According to the standard XML the default encoding is UTF-8, but it can be changed if you specify a <?xml version="1.0" encoding="otherEncoding"?>. Probably more correct to take it from there.
                
      was (Author:  alexlumpov):
    I have the same problem.
Template has russian letters. My template ecnoding is UTF-8. But my default system encoding is Cp1251.
If tomcat starts with -Dfile.encoding=UTF-8 everything is ok.
But if tomcat starts without this option I has exception: Invalid byte 2 of 2-byte UTF-8 sequence.

new method in 5.3 XMLTokenStream.openStream() has:
337: InputStreamReader rawReader = new InputStreamReader(rawStream); // used default charset
341: PrintWriter writer = new PrintWriter(bos);  // used default charset

This means that the byte stream is converted from the system encoding to UTF-8 and then back. During this transformation a number of characters are wasted. In my case the solution would be the following:
337: InputStreamReader rawReader = new InputStreamReader(rawStream, "UTF-8"); // used default charset
341: PrintWriter writer = new PrintWriter(new OutputStreamWriter(bos, "UTF-8"));  // used default charset

According to the standard XML the default encoding is UTF-8, but it can be changed if you specify a <?xml version="1.0" encoding="otherEncoding"?>. Probably more correct to take it from there.
                  
> Parsing template which contains Chinese (Maybe other double bytes) words throws MalformedByteSequenceException: Invalid byte 3 of 3-byte UTF-8 sequence.
> --------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: TAP5-1741
>                 URL: https://issues.apache.org/jira/browse/TAP5-1741
>             Project: Tapestry 5
>          Issue Type: Bug
>          Components: tapestry-core
>    Affects Versions: 5.3
>            Reporter: DH
>            Priority: Blocker
>         Attachments: Index.tml
>
>
> After upgrading to 5.3-rc-1, all my templates are not parsed successfully. The error message points to the line where there are Chinese words.
> Stack Trace below:
> Caused by: com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Invalid byte 3 of 3-byte UTF-8 sequence.
>         at com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.invalidByte(UTF8Reader.java:684)
>         at com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.read(UTF8Reader.java:432)
>         at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.load(XMLEntityScanner.java:1742)
>         at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.skipChar(XMLEntityScanner.java:1416)
>         at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2792)
>         at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
>         at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140)
>         at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
>         at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
>         at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
>         at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
>         at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
>         at org.apache.tapestry5.internal.services.XMLTokenStream.parse(XMLTokenStream.java:306)
>         at org.apache.tapestry5.internal.services.SaxTemplateParser.parse(SaxTemplateParser.java:163)
>         ... 85 more

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira