mgivney / easyb

Automatically exported from code.google.com/p/easyb
0 stars 0 forks source link

[maven-easyb-plugin] MalformedByteSequenceException when parsing a story file containing non-UTF-8 locale specific characters #174

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
======================================

1. Create a story file with non-UTF-8 encoding and some locale specific
characters, like below:

EasybEncodingIssue.story

------------------------

scenario 'Easyb should not throw an exception when parsing story file in
non-UTF-8 encoding', {
    given 'a file in ISO-8859-2 with a story which "given" clause contains
locale specific characters, eg. ąźć', {
    }

    when 'easyb parses this story file', {
    }

    then 'it should not throw MalformedByteSequenceException', {
    }
}

2. Run tests with: ~/project-folder/> mvn easyb:test

What is the expected output? What do you see instead?
=====================================================

The Maven build should be clean and succesfull, showing 1 scenario run and
0 failures. No exceptions. The actual output is as below:

~/project-folder/> mvn easyb:test
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building SomeProject
[INFO]    task-segment: [easyb:test]
[INFO] ------------------------------------------------------------------------
[INFO] [easyb:test {execution: default-cli}]
[INFO] Using easyb dependency org.easyb:easyb:jar:0.9.6:compile
[INFO] Using easyb dependency commons-cli:commons-cli:jar:1.1:compile
[INFO] Using easyb dependency org.codehaus.groovy:groovy-all:jar:1.6.0:compile
[INFO] Using easyb dependency junit:junit:jar:3.8.2:compile
[INFO] Using easyb dependency org.apache.ant:ant:jar:1.7.1:compile
[INFO] Using easyb dependency org.apache.ant:ant-launcher:jar:1.7.1:compile
[INFO] Using easyb dependency jline:jline:jar:0.9.94:compile
     [java] Running easyb encoding issue story (EasybEncodingIssue.story)
     [java] Scenarios run: 1, Failures: 0, Pending: 0, Time elapsed: 1.8 sec
     [java] 1 behavior ran with no failures
[INFO] ------------------------------------------------------------------------
[ERROR] FATAL ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Invalid byte 1 of 1-byte UTF-8 sequence.
[INFO] ------------------------------------------------------------------------
[INFO] Trace
com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException:
Invalid byte 1 of 1-byte UTF-8 sequence.
        at
com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.invalidByte(UTF8Reader.jav
a:674)
        at
com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.read(UTF8Reader.java:547)
        at
com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.load(XMLEntityScanner.j
ava:1742)
        at
com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.scanLiteral(XMLEntitySc
anner.java:1064)
        at
com.sun.org.apache.xerces.internal.impl.XMLScanner.scanAttributeValue(XMLScanner
.java:974)
        at
com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanAttribute(X
MLNSDocumentScannerImpl.java:460)
        at
com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElemen
t(XMLNSDocumentScannerImpl.java:277)
        at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentC
ontentDriver.next(XMLDocumentFragmentScannerImpl.java:2740)
        at
com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentS
cannerImpl.java:645)
        at
com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocum
entScannerImpl.java:140)
        at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocum
ent(XMLDocumentFragmentScannerImpl.java:508)
        at
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configu
ration.java:807)
        at
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configu
ration.java:737)
        at
com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:107)
        at
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXPa
rser.java:1205)
        at
com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXPar
serImpl.java:522)
        at groovy.util.XmlParser.parse(XmlParser.java:182)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.jav
a:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at
org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
        at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)
        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1061)
        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
        at
org.codehaus.groovy.runtime.InvokerHelper.invokePojoMethod(InvokerHelper.java:72
5)
        at
org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:716)
        at
org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN(ScriptBytecodeAd
apter.java:163)
        at org.easyb.maven.EasybExecutor.execute(EasybExecutor.groovy:53)
        at org.easyb.maven.EasybMojo.execute(EasybMojo.java:139)
        at
org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.ja
va:490)
        at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycl
eExecutor.java:694)
        at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(Defaul
tLifecycleExecutor.java:569)
        at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycle
Executor.java:539)
        at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures
(DefaultLifecycleExecutor.java:387)
        at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultL
ifecycleExecutor.java:348)
        at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExec
utor.java:180)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
        at
org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.jav
a:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
        at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
        at
org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
        at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8 seconds
[INFO] Finished at: Wed Mar 10 16:05:00 GMT+01:00 2010
[INFO] Final Memory: 7M/13M
[INFO] ------------------------------------------------------------------------

What version of the product are you using? On what operating system?
====================================================================

Apache Maven 2.2.1 (r801777; 2009-08-06 20:16:01+0100)
Java version: 1.6.0_01
Java home: /usr/local/jdk1.6.0_01/jre
Default locale: pl_PL, platform encoding: ISO-8859-2
OS name: "linux" version: "2.6.21-2-686" arch: "i386" Family: "unix"

org.easyb.maven-easyb-plugin.0.9.6

Please provide any additional information below.
================================================

This problem does not occur when running test stories from Eclipse with
easyb Eclipse plugin (v.0.0.15).

Original issue reported on code.google.com by gos...@gmail.com on 10 Mar 2010 at 3:24

GoogleCodeExporter commented 9 years ago

Original comment by ajglo...@gmail.com on 9 Apr 2010 at 7:36

GoogleCodeExporter commented 9 years ago
Hi! I have the same problem on Japanese environment.

Then I try to fix it.
The reason of this problem is that FileWriter class uses the system default 
character encoding.
(see http://java.sun.com/javase/6/docs/api/java/io/FileWriter.html)

Here is my patch, please merge it into source code:
org.easyb.report.XmlReportWriter.groovy

--- XmlReportWriter.groovy- Wed Feb 03 16:45:51 2010
+++ XmlReportWriter.groovy  Wed Jun 09 10:45:30 2010
@@ -101,7 +101,9 @@
     }

     public void writeReport(ResultsCollector results) {
-        Writer writer = new BufferedWriter(new FileWriter(new File(location)))
+        def fileOutputStream = new FileOutputStream(location)
+        def utf8OutputStream = new OutputStreamWriter(fileOutputStream, 
"UTF-8")
+        Writer writer = new BufferedWriter(utf8OutputStream)

         def xml = new MarkupBuilder(writer)

Original comment by ttan...@cybernet.co.jp on 9 Jun 2010 at 2:00

GoogleCodeExporter commented 9 years ago

Original comment by jeffrey....@gmail.com on 19 Dec 2010 at 6:13