Audit Plugin throws a NumberFormatException at run time

XMLWordPrintable

    • 2
    • Severity 3 - Minor

      Issue Summary

      Confluence may exhibit an error in atlassian-confluence.log during startup, generating the support.zip and when we hit this URL in the browser:

      • http://<confluence-url>/rest/auditing/1.0/statistics/database/usage

      Steps to Reproduce

      The problem was identified by analyzing the audit-plugin code in Confluence 7.7.x or later versions that contain the package com.atlassian.audit.database.usage. The relevant piece of code:

      private final DecimalFormat formatter = new DecimalFormat("#0.00");
      ...
      double percentage = actualCount / allowedCount; return Response.ok(new AuditDatabaseUsageJson(Double.parseDouble(formatter.format(percentage)))).build();
      

      Note that there's no explicit locale set for the DecimalFormat, so the system locale is used.

      The last line is the problem, it formats and then parses which blows up. Reproducible when changing the system locale and executing:

      // Force German locale
      DecimalFormatSymbols symbols = new DecimalFormatSymbols(Locale.GERMAN);
      DecimalFormat formatter = new DecimalFormat("#0.00", symbols);
      double percentage = 79.0 / 7.9E-6;
      Double.parseDouble(formatter.format(percentage));
      

      Expected Results

      The calculation is performed as expected

      Actual Results

      The calculation errors out due to code bug and this exception are thrown in the atlassian-confluence.log file:

      2020-10-16 11:15:58,431 ERROR [https-jsse-nio2-10.3.25.36-443-exec-10] [database.usage.rest.AuditDatabaseUsageRestResource] getUsage Unexpected exception :
      -- url: /rest/auditing/latest/statistics/database/usage | traceId: 88147af79521bfc7 | userName: anonymous
      java.lang.NumberFormatException: For input string: "0,00"
      at java.base/jdk.internal.math.FloatingDecimal.readJavaFormatString(Unknown Source)
      at java.base/jdk.internal.math.FloatingDecimal.parseDouble(Unknown Source)
      at java.base/java.lang.Double.parseDouble(Unknown Source)
      at com.atlassian.audit.database.usage.rest.AuditDatabaseUsageRestResource.getUsage(AuditDatabaseUsageRestResource.java:52)
      

      Workaround

      1. Shutdown Confluence
      2. Backup C:\Program Files\Atlassian\Confluence\confluence\WEB-INF\classes\log4j.properties
      3. Edit C:\Program Files\Atlassian\Confluence\confluence\WEB-INF\classes\log4j.properties
        • Add in this new line at the bottom:
          log4j.logger.com.atlassian.audit.database.usage.rest.AuditDatabaseUsageRestResource=FATAL
          
      4. Restart Confluence

            Assignee:
            Saquia Naz
            Reporter:
            Artur J
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: