#87 division by zero

closed-fixed
nobody
None
7
2008-04-01
2007-05-25
Jan Dockx
No

This should be version 0.3.1 (because in my m2 repo we see: stat-cvs-0.3.1-StatSCM.jar).

INFO: writing chart 'Author Activity' to activity.png
May 25, 2007 10:37:21 PM net.sf.statcvs.charts.ChartImage write
INFO: writing chart 'Activity by Hour of Day for jandockx' to activity_time_jandockx.png
May 25, 2007 10:37:23 PM net.sf.statcvs.charts.ChartImage write
INFO: writing chart 'Activity by Day of Week for jandockx' to activity_day_jandockx.png
[INFO] ------------------------------------------------------------------------
[ERROR] FATAL ERROR
[INFO] ------------------------------------------------------------------------
[INFO] / by zero
[INFO] ------------------------------------------------------------------------
[INFO] Trace
java.lang.ArithmeticException: / by zero
at net.sf.statcvs.pages.DeveloperPageMaker.getNumberAndPercentage(DeveloperPageMaker.java:133)
at net.sf.statcvs.pages.DeveloperPageMaker.toFile(DeveloperPageMaker.java:84)
at net.sf.statcvs.pages.AllDevelopersPageMaker.toFile(AllDevelopersPageMaker.java:76)
at net.sf.statcvs.pages.ReportSuiteMaker.toFile(ReportSuiteMaker.java:77)
at net.sf.statsvn.Main.generateDefaultHTMLSuite(Main.java:300)
at net.sf.statsvn.Main.generateDefaultHTMLSuite(Main.java:230)
at net.sf.statscm.StatScmMojo.doSvnStats(StatScmMojo.java:155)
at net.sf.statscm.StatScmMojo.executeReport(StatScmMojo.java:125)
at org.apache.maven.reporting.AbstractMavenReport.generate(AbstractMavenReport.java:101)
at org.apache.maven.plugins.site.SiteMojo.generateReportsPages(SiteMojo.java:802)
at org.apache.maven.plugins.site.SiteMojo.execute(SiteMojo.java:301)
at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:443)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:539)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:480)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:459)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:311)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:278)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:143)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:334)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:125)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:272)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
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: 2 minutes 38 seconds
[INFO] Finished at: Fri May 25 22:37:24 CEST 2007
[INFO] Final Memory: 22M/40M
[INFO] ------------------------------------------------------------------------
jand@cvs:beedraz-examples>

Discussion

  • Jan Dockx
    Jan Dockx
    2007-05-25

    Logged In: YES
    user_id=189935
    Originator: YES

    The current code with the problem is

    /**
    127 : * returns the percentage of a given total count and the count
    128 : * @param value
    129 : * @param total
    130 : * @return String percentage string
    131 : */
    132 : private String getNumberAndPercentage(int value, int total) {
    133 : final int percentTimes10 = (value * 1000) / total;
    134 : final double percent = percentTimes10 / 10.0;
    135 : return value + " (" + Double.toString(percent) + "%)";
    136 : }

    I suggest changing it to:

    private final static NumberFormat PERCENT_FORMAT = NumberFormat.getPercentInstance();

    static {
    PERCENT_FORMAT.setMinimumFractionDigits(1);
    PERCENT_FORMAT.setMaximumFractionDigits(1);
    }

    /**
    * returns the percentage of a given total count and the count
    * @param value
    * @param total
    * @return String percentage string
    */
    private String getNumberAndPercentage(int value, int total) {
    final double factor = (double)value / (double)total;
    return value + " (" + PERCENT_FORMAT.format(factor) + ")";
    }

    This will work, because division by zero is not a problem with doubles: you get NaN (and the formatter will format that too).

     
  • Jan Dockx
    Jan Dockx
    2007-05-25

    • priority: 5 --> 7
     
  • Logged In: YES
    user_id=358115
    Originator: NO

    Hi Jan

    Thanks for the fix, it is committed now.

    Benoit

     
    • status: open --> closed-fixed