SonarQube Plugins
  1. SonarQube Plugins
  2. SONARPLUGINS-434

org.dom4j.DocumentException when Hudson pages contain non-ascii chars

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: BUILD-STABILITY-1.0.1
    • Fix Version/s: BUILD-STABILITY-1.1
    • Component/s: Build Stability
    • Labels:
      None
    • Environment:
      OS : Linux
      Java : java version "1.6.0_16"
      Sonar : 1.12
      HUdson : 1.352
    • Patch Submitted:
      Yes
    • Number of attachments :
      1

      Description

      The trace is :

      [INFO]  CI URL: Hudson:http://localhost/hudson/job/F4
      [ERROR]  org.dom4j.DocumentException: Error on line 1 of document  : Invalid byte 2 of 3-byte UTF-8 sequence. Nested exception: Invalid byte 2 of 3-byte UTF-8 sequence.
      java.lang.RuntimeException: org.dom4j.DocumentException: Error on line 1 of document  : Invalid byte 2 of 3-byte UTF-8 sequence. Nested exception: Invalid byte 2 of 3-byte UTF-8 sequence.
      	at org.sonar.plugins.buildstability.ci.CiConnector.executeMethod(CiConnector.java:105) [sonar-build-stability-plugin-1.0.1-20100322160633.jar:na]
      	at org.sonar.plugins.buildstability.ci.CiConnector.executeGetMethod(CiConnector.java:91) [sonar-build-stability-plugin-1.0.1-20100322160633.jar:na]
      	at org.sonar.plugins.buildstability.ci.CiConnector.getLastBuild(CiConnector.java:44) [sonar-build-stability-plugin-1.0.1-20100322160633.jar:na]
      	at org.sonar.plugins.buildstability.ci.CiConnector.getBuildsSince(CiConnector.java:77) [sonar-build-stability-plugin-1.0.1-20100322160633.jar:na]
      	at org.sonar.plugins.buildstability.BuildStabilitySensor.analyse(BuildStabilitySensor.java:82) [sonar-build-stability-plugin-1.0.1-20100322160633.jar:na]
      	at org.sonar.batch.core.SensorsExecutor.execute(SensorsExecutor.java:59) [sonar-core-maven-plugin-20100322160633.jar:na]
      	at org.sonar.batch.Batch.executeJobs(Batch.java:91) [sonar-core-maven-plugin-20100322160633.jar:na]
      	at org.sonar.batch.Batch.analyse(Batch.java:79) [sonar-core-maven-plugin-20100322160633.jar:na]
      	at org.sonar.batch.Batch.start(Batch.java:54) [sonar-core-maven-plugin-20100322160633.jar:na]
      	at org.sonar.batch.BatchMojo.executeBatch(BatchMojo.java:145) [sonar-core-maven-plugin-20100322160633.jar:na]
      	at org.sonar.batch.BatchMojo.execute(BatchMojo.java:137) [sonar-core-maven-plugin-20100322160633.jar:na]
      	at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490) [maven-2.2.1-uber.jar:2.2.1]
      	at hudson.maven.agent.PluginManagerInterceptor.executeMojo(PluginManagerInterceptor.java:182) [maven-interceptor-1.352.jar:na]
      	at org.codehaus.mojo.sonar.Bootstraper.executeMojo(Bootstraper.java:82) [sonar-maven-plugin-1.0-beta-1.jar:na]
      	at org.codehaus.mojo.sonar.Bootstraper.start(Bootstraper.java:65) [sonar-maven-plugin-1.0-beta-1.jar:na]
      	at org.codehaus.mojo.sonar.SonarMojo.execute(SonarMojo.java:117) [sonar-maven-plugin-1.0-beta-1.jar:na]
      	at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490) [maven-2.2.1-uber.jar:2.2.1]
      	at hudson.maven.agent.PluginManagerInterceptor.executeMojo(PluginManagerInterceptor.java:182) [maven-interceptor-1.352.jar:na]
      	at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694) [maven-2.2.1-uber.jar:na]
      	at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:569) [maven-2.2.1-uber.jar:na]
      	at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:539) [maven-2.2.1-uber.jar:na]
      	at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387) [maven-2.2.1-uber.jar:na]
      	at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:284) [maven-2.2.1-uber.jar:na]
      	at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180) [maven-2.2.1-uber.jar:na]
      	at org.apache.maven.lifecycle.LifecycleExecutorInterceptor.execute(LifecycleExecutorInterceptor.java:65) [maven-interceptor-1.352.jar:na]
      	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328) [maven-2.2.1-uber.jar:2.2.1]
      	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138) [maven-2.2.1-uber.jar:2.2.1]
      	at org.apache.maven.cli.MavenCli.main(MavenCli.java:362) [maven-2.2.1-uber.jar:2.2.1]
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [na:1.6.0_16]
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [na:1.6.0_16]
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [na:1.6.0_16]
      	at java.lang.reflect.Method.invoke(Method.java:597) [na:1.6.0_16]
      	at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315) [classworlds-1.1.jar:1.1]
      	at org.codehaus.classworlds.Launcher.launch(Launcher.java:255) [classworlds-1.1.jar:1.1]
      	at hudson.maven.agent.Main.launch(Main.java:165) [maven-agent-1.352.jar:na]
      	at hudson.maven.MavenBuilder.call(MavenBuilder.java:159) [na:na]
      	at hudson.maven.MavenModuleSetBuild$Builder.call(MavenModuleSetBuild.java:688) [na:na]
      	at hudson.maven.MavenModuleSetBuild$Builder.call(MavenModuleSetBuild.java:632) [na:na]
      	at hudson.remoting.UserRequest.perform(UserRequest.java:114) [remoting-1.352.jar:na]
      	at hudson.remoting.UserRequest.perform(UserRequest.java:48) [remoting-1.352.jar:na]
      	at hudson.remoting.Request$2.run(Request.java:270) [remoting-1.352.jar:na]
      	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441) [na:1.6.0_16]
      	at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) [na:1.6.0_16]
      	at java.util.concurrent.FutureTask.run(FutureTask.java:138) [na:1.6.0_16]
      	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [na:1.6.0_16]
      	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [na:1.6.0_16]
      	at java.lang.Thread.run(Thread.java:619) [na:1.6.0_16]
      Caused by: org.dom4j.DocumentException: Error on line 1 of document  : Invalid byte 2 of 3-byte UTF-8 sequence. Nested exception: Invalid byte 2 of 3-byte UTF-8 sequence.
      	at org.dom4j.io.SAXReader.read(SAXReader.java:482) [dom4j-1.6.1.jar:1.6.1]
      	at org.dom4j.io.SAXReader.read(SAXReader.java:343) [dom4j-1.6.1.jar:1.6.1]
      	at org.sonar.plugins.buildstability.ci.CiConnector.executeMethod(CiConnector.java:103) [sonar-build-stability-plugin-1.0.1-20100322160633.jar:na]
      	... 46 common frames omitted
      

      Somme developpers use non ascii characters (like "" or "") in their commit messages.
      These messages are then read by Hudson and dispalyed on build pages. It's when CiConnector class read these pages that the error occur.
      Mainly, it's because of the SaxReader and how it reads the response stream.
      I've modififed the classe CiConnector to deal with Hudson "badly" encoded HTML pages, by changing the line

       
      return new SAXReader().read(method.getResponseBodyAsStream());
      

      to

       
      return new SAXReader().read(new InputStreamReader(method.getResponseBodyAsStream(),"UTF-8"));
      

      The patch is attached if interested.

      Regards,

      KL.

        Issue Links

          Activity

          Hide
          Evgeny Mandrikov added a comment -

          Thanks for your patch - I'll go to apply it.

          Show
          Evgeny Mandrikov added a comment - Thanks for your patch - I'll go to apply it.
          Hide
          Evgeny Mandrikov added a comment -

          Patch was applied.
          Thank you.

          Show
          Evgeny Mandrikov added a comment - Patch was applied. Thank you.
          Hide
          Guillaume Soldera added a comment -

          Hi,

          I've got the same issue on my project but the patch mentionned doesn't fix it.

          Actually, my Hudson page was encoded in ISO-8859-1 whereas this correction only forced to UTF-8.

          Here's a new patch who analyze XML and Request Headers to get any encoding declaration :

          SAXReader sax = new SAXReader();
          			
          String response = method.getResponseBodyAsString();
          Pattern xmlPattern = Pattern.compile("<\\?xml(?: \\w*=\".*\") encoding=\"(.*)\".*");
          Matcher matcher = xmlPattern.matcher(response);
          if (matcher.matches()) {
          	sax.setEncoding(matcher.group(1));
          } else {
          	String contentType = method.getResponseHeader("Content-Type").getValue();
          	Pattern pattern = Pattern.compile(".*charset=([^;]*).*");
          	Matcher m = pattern.matcher(contentType);
          	if (m.matches()) {
          		sax.setEncoding(m.group(1));
          	}
          }
          return sax.read(method.getResponseBodyAsStream());
          

          May this help
          Regards

          Guillaume

          Show
          Guillaume Soldera added a comment - Hi, I've got the same issue on my project but the patch mentionned doesn't fix it. Actually, my Hudson page was encoded in ISO-8859-1 whereas this correction only forced to UTF-8. Here's a new patch who analyze XML and Request Headers to get any encoding declaration : SAXReader sax = new SAXReader(); String response = method.getResponseBodyAsString(); Pattern xmlPattern = Pattern.compile( "<\\?xml(?: \\w*=\" .*\ ") encoding=\" (.*)\ ".*" ); Matcher matcher = xmlPattern.matcher(response); if (matcher.matches()) { sax.setEncoding(matcher.group(1)); } else { String contentType = method.getResponseHeader( "Content-Type" ).getValue(); Pattern pattern = Pattern.compile( ".*charset=([^;]*).*" ); Matcher m = pattern.matcher(contentType); if (m.matches()) { sax.setEncoding(m.group(1)); } } return sax.read(method.getResponseBodyAsStream()); May this help Regards Guillaume
          Hide
          Evgeny Mandrikov added a comment -

          Hi Guillaume,

          Good point! So, reopening this issue.

          Show
          Evgeny Mandrikov added a comment - Hi Guillaume, Good point! So, reopening this issue.
          Hide
          Evgeny Mandrikov added a comment -

          New patch was applied.

          Thanks, Guillaume.

          Show
          Evgeny Mandrikov added a comment - New patch was applied. Thanks, Guillaume.

            People

            • Assignee:
              Evgeny Mandrikov
              Reporter:
              Khaled LABIDI
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: