cnescatlab / sonar-cnes-report

Generates analysis reports from SonarQube web API.
GNU General Public License v3.0
476 stars 160 forks source link

NPE during Report Generation with SonarQube 9.9.1.69595 #415

Open Zuplyx opened 2 months ago

Zuplyx commented 2 months ago

Describe the bug

Report creation fails with a NullPointerException.

To reproduce

Steps to reproduce the behavior.

Run the standalone jar: java -jar sonar-cnes-report-4.3.0.jar -p PROJECT_KEY -b trunk -s http://SERVER_URL:8090/

Expected behavior

A clear and concise description of what you expected to happen.

The report should complete successfully.

Screenshots & log

Stacktrace:

Exception in thread "main" java.lang.NullPointerException
        at fr.cnes.sonar.report.providers.facets.AbstractFacetsProvider.extractTimeValuesFromJsonObject(AbstractFacetsProvider.java:176)
        at fr.cnes.sonar.report.providers.facets.AbstractFacetsProvider.getTimeFacetsAbstract(AbstractFacetsProvider.java:143)
        at fr.cnes.sonar.report.providers.facets.FacetsProviderStandalone.getTimeFacets(FacetsProviderStandalone.java:65)
        at fr.cnes.sonar.report.factory.ReportModelFactory.create(ReportModelFactory.java:121)
        at fr.cnes.sonar.report.ReportCommandLine.execute(ReportCommandLine.java:145)
        at fr.cnes.sonar.report.ReportCommandLine.main(ReportCommandLine.java:82)

According to the stacktrace the report creation fails in fr.cnes.sonar.report.providers.facets.AbstractFacetsProvider#extractTimeValuesFromJsonObject when trying to process this json {"date":"2012-01-01T00:11:23+0100"}

User environment

Please complete the following information.

Proposed fix:

Applying the following patch fixes the issue:


diff --git a/src/main/java/fr/cnes/sonar/report/providers/facets/AbstractFacetsProvider.java b/src/main/java/fr/cnes/sonar/report/providers/facets/AbstractFacetsProvider.java
index 7a38c15..111e98d 100644
--- a/src/main/java/fr/cnes/sonar/report/providers/facets/AbstractFacetsProvider.java
+++ b/src/main/java/fr/cnes/sonar/report/providers/facets/AbstractFacetsProvider.java
@@ -169,11 +169,12 @@ public abstract class AbstractFacetsProvider extends AbstractDataProvider {
         // For each measure (date/value) inside the "history" attribute of the measure
         for(JsonElement history : metric.get(HISTORY).getAsJsonArray()) {
             JsonObject measure = history.getAsJsonObject();
+            // Get data as String because Word charts take Strings as input
+            String value = measure.get("date").getAsString();
             // Convert Date from SonarQube format to Excel
             double date = DateConverter.sonarQubeDateToExcelDate(
-                measure.get("date").getAsString());
-            // Get data as String because Word charts take Strings as input
-            String value = measure.get("value").getAsString();
+                value);
+
             TimeValue v = new TimeValue(date, value);
             values.add(v);
         }
Zuplyx commented 2 months ago

After an update to the most recent LTS version (9.9.6.92038) of SonarQube this issue still persists.