Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-2953

NumberFormatException when collecting Crap4J analysis files

    XMLWordPrintable

Details

    • Improvement
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • crap4j-plugin
    • None
    • Platform: Other, OS: Windows XP

    Description

      Hello Daniel,

      i am trying to use the crap4j plugin under hudson. i integrated crap4j into our
      ant script and the output is generated well (report.xml as well as the html report).

      when i try to run crap4j (v 0.5) under hudson (1.279), we get error messages like:

      ...
      BUILD SUCCESSFUL
      Total time: 17 seconds
      [CRAP4J] Collecting Crap4J analysis files...
      FATAL: For input string: "?"
      java.lang.NumberFormatException: For input string: "?"
      at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1224)
      at java.lang.Double.parseDouble(Double.java:510)
      at com.schneide.crap4j.reader.ReportReader.parseStatistics(ReportReader.java:141)
      at com.schneide.crap4j.reader.ReportReader.parseData(ReportReader.java:130)
      at hudson.plugins.crap4j.Crap4JPublisher.perform(Crap4JPublisher.java:93)
      at
      hudson.tasks.BuildStepCompatibilityLayer.perform(BuildStepCompatibilityLayer.java:33)
      at
      hudson.model.AbstractBuild$AbstractRunner.performAllBuildStep(AbstractBuild.java:324)
      at
      hudson.model.AbstractBuild$AbstractRunner.performAllBuildStep(AbstractBuild.java:312)
      at hudson.model.Build$RunnerImpl.post2(Build.java:132)
      at hudson.model.AbstractBuild$AbstractRunner.post(AbstractBuild.java:297)
      at hudson.model.Run.run(Run.java:862)
      at hudson.model.Build.run(Build.java:88)
      at hudson.model.ResourceController.execute(ResourceController.java:70)
      at hudson.model.Executor.run(Executor.java:90)

      when i tried to find the problem, i diffed the generated report from ant with
      the report after the crap4j plugin under hudson and
      i get differences in these lines:

      1.) ant:
      <stats>
      <name>
      Method Crap Stats
      </name>
      <totalCrap>
      60036,00
      </totalCrap>
      <crap>
      7,16
      </crap>
      <median>
      2,00
      </median>
      <average>
      7,16
      </average>
      <stdDev>
      36,86
      </stdDev>

      2.) hudson:
      <stats>
      <name>
      Method Crap Stats
      </name>
      <totalCrap>
      ?
      </totalCrap>
      <crap>
      ?
      </crap>
      <median>
      2,00
      </median>
      <average>
      ?
      </average>
      <stdDev>
      ?
      </stdDev>

      i think this is the point where the plugin gets the errors.

      when i copy the report from ant into crap4j output folder for hudson and run an
      ant build with just the crap4j task again via hudson (without running tests,
      just do the report), the report is modified with the "?" again.

      in ant i use crap4j 1.1.6 to generate the report, the report is approx. 5 MBs of
      size.

      i'm not sure whether this is a defect in the plugin nor do i know what to do
      else - maybe you have any ideas ?

      best greets,
      oliver

      Attachments

        Activity

          dlindner dlindner added a comment -

          Hello Oliver,

          this seems to be a bug, though i cannot reproduce it on my setting using the
          exact same versions.

          Let me repeat your setting as i understand it:

          • You added the crap4j ant tasks to your build script, creating a report.xml
          • If you run your build script locally, numbers like the total crap shows up
            like 60000,00 (indicating a german locale) in the report.xml
          • If you run your build script within hudson, the total crap shows up like "?"
            in the report.xml

          The crap4j hudson plugin has a read-only connection to the report.xml, so it
          won't change the numbers. I didn't fully understand your manual manipulations to
          the report.xml you describe in the last section.

          I am aware that crap4j has some issues with locales. This might be the origin
          for this problem. What i can do right now is to add some unit tests to the
          crap4j plugin characterizing its behaviour with your inputs and perhaps make it
          more robust to locale changes.

          What i want you to do is:

          • Tell me what systems you generate the report.xml on. Are these set to german
            locales or is just the local build maschine set to german and the hudson server
            is set to english/no locale?
          • Perhaps try to set a specific locale on the hudson build machine.
          • Set up a job within hudson that does nothing. No build file, no SCM, etc. Copy
            your different report.xml files to a location in the workspace and configure the
            crap4j plugin to process it. Perform a few runs with different report.xml files
            and report your conclusions about them.

          I will work on this issue today. The rest of the week is more or less assigned
          to other tasks, so hopefully we find a fix right away.

          dlindner dlindner added a comment - Hello Oliver, this seems to be a bug, though i cannot reproduce it on my setting using the exact same versions. Let me repeat your setting as i understand it: You added the crap4j ant tasks to your build script, creating a report.xml If you run your build script locally, numbers like the total crap shows up like 60000,00 (indicating a german locale) in the report.xml If you run your build script within hudson, the total crap shows up like "?" in the report.xml The crap4j hudson plugin has a read-only connection to the report.xml, so it won't change the numbers. I didn't fully understand your manual manipulations to the report.xml you describe in the last section. I am aware that crap4j has some issues with locales. This might be the origin for this problem. What i can do right now is to add some unit tests to the crap4j plugin characterizing its behaviour with your inputs and perhaps make it more robust to locale changes. What i want you to do is: Tell me what systems you generate the report.xml on. Are these set to german locales or is just the local build maschine set to german and the hudson server is set to english/no locale? Perhaps try to set a specific locale on the hudson build machine. Set up a job within hudson that does nothing. No build file, no SCM, etc. Copy your different report.xml files to a location in the workspace and configure the crap4j plugin to process it. Perform a few runs with different report.xml files and report your conclusions about them. I will work on this issue today. The rest of the week is more or less assigned to other tasks, so hopefully we find a fix right away.
          dlindner dlindner added a comment -

          Created an attachment (id=538)
          Crap4J Plugin with better localization support

          dlindner dlindner added a comment - Created an attachment (id=538) Crap4J Plugin with better localization support
          dlindner dlindner added a comment -

          Oliver,

          i created a bugfix intermediate build and attached it to this issue.
          Download it from
          https://hudson.dev.java.net/nonav/issues/showattachment.cgi/538/crap4j.hpi

          You will need to use the "upload plugin" functionality of the "advanced" tab in
          the plugin manager.

          Please install the snapshot release and tell me if it changed anything.
          In version 0.5, the plugin always assumes english (international) number format.
          In this version, the plugin uses the platform locale to manage the number format
          (just like crap4j does when writing the report.xml).

          dlindner dlindner added a comment - Oliver, i created a bugfix intermediate build and attached it to this issue. Download it from https://hudson.dev.java.net/nonav/issues/showattachment.cgi/538/crap4j.hpi You will need to use the "upload plugin" functionality of the "advanced" tab in the plugin manager. Please install the snapshot release and tell me if it changed anything. In version 0.5, the plugin always assumes english (international) number format. In this version, the plugin uses the platform locale to manage the number format (just like crap4j does when writing the report.xml).
          oliva oliva added a comment -

          Hello Daniel,

          thank you for your very quick response and your fix. i tried it - it didnt
          change very much - the exception is a bit different now:
          [CRAP4J] Collecting Crap4J analysis files...
          FATAL: Unparseable number: "?" for ?
          java.lang.NumberFormatException: Unparseable number: "?" for ?
          at com.schneide.crap4j.reader.util.NumericalParser.parseDouble
          (NumericalParser.java:26)
          at com.schneide.crap4j.reader.ReportReader.parseStatistics
          (ReportReader.java:143)
          at com.schneide.crap4j.reader.ReportReader.parseData(ReportReader.java:131)
          at hudson.plugins.crap4j.Crap4JPublisher.perform(Crap4JPublisher.java:93)

          thank you for your comments regarding the locale settings - i'm sure that your
          plugin has nothing to to with my errors i tried it with some modifications
          (so that running crap4j under hudson does not create a report and storing the
          ok report from ant in the hudson project dir) an the plugin worked well (the
          new version from you - didn't try with 0.5).

          i will see why hudson/ant creates another report than commandline/ant (both on
          the same system).

          thanks a lot,
          oliver

          oliva oliva added a comment - Hello Daniel, thank you for your very quick response and your fix. i tried it - it didnt change very much - the exception is a bit different now: [CRAP4J] Collecting Crap4J analysis files... FATAL: Unparseable number: "?" for ? java.lang.NumberFormatException: Unparseable number: "?" for ? at com.schneide.crap4j.reader.util.NumericalParser.parseDouble (NumericalParser.java:26) at com.schneide.crap4j.reader.ReportReader.parseStatistics (ReportReader.java:143) at com.schneide.crap4j.reader.ReportReader.parseData(ReportReader.java:131) at hudson.plugins.crap4j.Crap4JPublisher.perform(Crap4JPublisher.java:93) thank you for your comments regarding the locale settings - i'm sure that your plugin has nothing to to with my errors i tried it with some modifications (so that running crap4j under hudson does not create a report and storing the ok report from ant in the hudson project dir) an the plugin worked well (the new version from you - didn't try with 0.5). i will see why hudson/ant creates another report than commandline/ant (both on the same system). thanks a lot, oliver
          dlindner dlindner added a comment -

          Hello Oliver,

          sorry to hear i couldn't help you much. I leave this issue open until you've
          found the source of the problem. Please documentate it here. The crap4j plugin
          version might become version 0.6 soon.

          I worked a bit on the issue adding your last comment. The code in question
          effectively does the following:

          ------------------
          import java.text.NumberFormat;
          import java.util.Locale;

          import junit.framework.TestCase;

          public class TryingToGetQuestionMarkTest extends TestCase {

          public void testHowNumberFormatMightSpitOutQuestionMark()

          { Locale myLocale = Locale.ROOT; // Change this to different settings NumberFormat nf = NumberFormat.getInstance(myLocale); nf.setMaximumFractionDigits(2); nf.setMinimumFractionDigits(2); nf.setGroupingUsed(false); assertEquals("?", nf.format(60036.00F)); }

          }
          ------------------

          I cannot think of a strange enough locale that would NumberFormat make spit out
          a question mark instead of a number. If you can make this test pass in your
          hudson (with myLocale set to Locale.getDefault()), that might be strong
          indicator for locale related problems.

          Another idea i got: Is it possible you run your hudson jobs with a different
          java VM than via command line?

          It's good to hear my plugin isn't the culprit, though.

          dlindner dlindner added a comment - Hello Oliver, sorry to hear i couldn't help you much. I leave this issue open until you've found the source of the problem. Please documentate it here. The crap4j plugin version might become version 0.6 soon. I worked a bit on the issue adding your last comment. The code in question effectively does the following: ------------------ import java.text.NumberFormat; import java.util.Locale; import junit.framework.TestCase; public class TryingToGetQuestionMarkTest extends TestCase { public void testHowNumberFormatMightSpitOutQuestionMark() { Locale myLocale = Locale.ROOT; // Change this to different settings NumberFormat nf = NumberFormat.getInstance(myLocale); nf.setMaximumFractionDigits(2); nf.setMinimumFractionDigits(2); nf.setGroupingUsed(false); assertEquals("?", nf.format(60036.00F)); } } ------------------ I cannot think of a strange enough locale that would NumberFormat make spit out a question mark instead of a number. If you can make this test pass in your hudson (with myLocale set to Locale.getDefault()), that might be strong indicator for locale related problems. Another idea i got: Is it possible you run your hudson jobs with a different java VM than via command line? It's good to hear my plugin isn't the culprit, though.
          oliva oliva added a comment -

          hello daniel,

          in the meantime i tried some settings with locale and the actual result is:
          1.) in a little testproject everything works fine.
          2.) i have a project build with some subprojects. as the testproject worked out
          fine, i tried another one of my subprojects and tratra: only 1 subproject (the
          one i started with) results in "?" in the report.xml, the others work fine
          3.) the subproject i started with and started this entry now produces ? in the
          report.xml under ant as well as in hudson (within my first tests with crap4j it
          just did in hudson)

          @3: i did changes at some points (locale settings on my windows, locale settings
          in crap4j java ant task, ..) and just tried out my project under hudson getting
          the ? in the result.xml.
          when i noticed that i also get the ? under ant i revoked my changes - but still
          get the ? in the report.

          i will try to find out what happens/happened. as i am a bit busy at work, i
          can't guarantee when i will get all subprojects to run - but i'll post it here.

          lg,
          oliver

          oliva oliva added a comment - hello daniel, in the meantime i tried some settings with locale and the actual result is: 1.) in a little testproject everything works fine. 2.) i have a project build with some subprojects. as the testproject worked out fine, i tried another one of my subprojects and tratra: only 1 subproject (the one i started with) results in "?" in the report.xml, the others work fine 3.) the subproject i started with and started this entry now produces ? in the report.xml under ant as well as in hudson (within my first tests with crap4j it just did in hudson) @3: i did changes at some points (locale settings on my windows, locale settings in crap4j java ant task, ..) and just tried out my project under hudson getting the ? in the result.xml. when i noticed that i also get the ? under ant i revoked my changes - but still get the ? in the report. i will try to find out what happens/happened. as i am a bit busy at work, i can't guarantee when i will get all subprojects to run - but i'll post it here. lg, oliver
          oliva oliva added a comment -

          hello daniel,

          another question regarding my tests: is it possible to merge multiple report.xml
          files within the crap4j/hudson plugin ?
          lets assume a fileset like **/target/crap4j/report.xml should find 2 reports:
          proj1/target/crap4j/report.xml and proj2/target/crap4j/report.xml. actually only
          one report is taken for the visualized report. is that what the plugin should do
          (take the first report that is found) or do i something wrong ?

          lg & thanks a lot,
          oliver

          oliva oliva added a comment - hello daniel, another question regarding my tests: is it possible to merge multiple report.xml files within the crap4j/hudson plugin ? lets assume a fileset like **/target/crap4j/report.xml should find 2 reports: proj1/target/crap4j/report.xml and proj2/target/crap4j/report.xml. actually only one report is taken for the visualized report. is that what the plugin should do (take the first report that is found) or do i something wrong ? lg & thanks a lot, oliver
          dlindner dlindner added a comment -

          Hello Oliver,

          currently, the plugin only handles the first crap report file found by the
          pattern, that's true. Merging multiple reports would require the plugin to
          recalculate the overall numbers. This isn't too complicated, but maybe unstable
          if the two crap reports were taken with different parameter sets e.g. for the
          crap threshold.

          If you need this functionality, i would like you to open a new issue (request
          for enhancement) and gather thoughts there. Perhaps others chime in and want
          this feature, too. I'm willing to provide it, it may take some time, though.

          dlindner dlindner added a comment - Hello Oliver, currently, the plugin only handles the first crap report file found by the pattern, that's true. Merging multiple reports would require the plugin to recalculate the overall numbers. This isn't too complicated, but maybe unstable if the two crap reports were taken with different parameter sets e.g. for the crap threshold. If you need this functionality, i would like you to open a new issue (request for enhancement) and gather thoughts there. Perhaps others chime in and want this feature, too. I'm willing to provide it, it may take some time, though.
          dlindner dlindner added a comment -

          I moved the additional request for enhancement (multiple reports) to a new issue
          2995.
          https://hudson.dev.java.net/issues/show_bug.cgi?id=2995

          The report parsing is now locale dependent. This might have caused trouble on
          non-english platforms, but wasn't the cause for this issue. So i'm closing it as
          FIXED though i fixed a slightly different problem.

          This will be released in 0.6

          dlindner dlindner added a comment - I moved the additional request for enhancement (multiple reports) to a new issue 2995. https://hudson.dev.java.net/issues/show_bug.cgi?id=2995 The report parsing is now locale dependent. This might have caused trouble on non-english platforms, but wasn't the cause for this issue. So i'm closing it as FIXED though i fixed a slightly different problem. This will be released in 0.6
          oliva oliva added a comment -

          finally i found the problem that resulted with "?" for some values in the
          report.xml.

          we do tracing via AspectJ and had the Aspect.aj file among our classfiles. it
          seems that this confuses crap4j (not the hudson plugin) to produce the question
          marks in the report. the hudson plugin then runs into the named exceptions while
          parsing the report.xml.

          unfortunately the aspect.aj file was checked in between my local tests with
          ant/crap4j and my tests with hudson/crap4j - that was misleading me to start
          this issue.

          thanks for helping !

          lg,
          oliver

          oliva oliva added a comment - finally i found the problem that resulted with "?" for some values in the report.xml. we do tracing via AspectJ and had the Aspect.aj file among our classfiles. it seems that this confuses crap4j (not the hudson plugin) to produce the question marks in the report. the hudson plugin then runs into the named exceptions while parsing the report.xml. unfortunately the aspect.aj file was checked in between my local tests with ant/crap4j and my tests with hudson/crap4j - that was misleading me to start this issue. thanks for helping ! lg, oliver

          People

            dlindner dlindner
            oliva oliva
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: