Skip to content
This repository has been archived by the owner on Jan 28, 2021. It is now read-only.

wkt-wickedcharts: NPE when invalid data is provided #29

Open
danhaywood opened this issue Oct 13, 2017 · 3 comments
Open

wkt-wickedcharts: NPE when invalid data is provided #29

danhaywood opened this issue Oct 13, 2017 · 3 comments

Comments

@danhaywood
Copy link
Contributor

from isisaddons-legacy/isis-wicket-wickedcharts#2

With the current Java Math demo data in the KitchenSink application trying to show a summarychart leads to the following exception:

Caused by: java.lang.NullPointerException
    at java.math.BigDecimal.compareTo(BigDecimal.java:2554)
    at java.math.BigDecimal.min(BigDecimal.java:2665)
    at org.isisaddons.wicket.wickedcharts.cpt.ui.summarychart.CollectionContentsAsSummaryChart.minOf(CollectionContentsAsSummaryChart.java:163)
    at org.isisaddons.wicket.wickedcharts.cpt.ui.summarychart.CollectionContentsAsSummaryChart.createChartValue(CollectionContentsAsSummaryChart.java:119)
    at org.isisaddons.wicket.wickedcharts.cpt.ui.summarychart.CollectionContentsAsSummaryChart.buildGui(CollectionContentsAsSummaryChart.java:101)
    at org.isisaddons.wicket.wickedcharts.cpt.ui.summarychart.CollectionContentsAsSummaryChart.onModelChanged(CollectionContentsAsSummaryChart.java:168)
@danhaywood
Copy link
Contributor Author

danhaywood commented Oct 13, 2017

martin-g:

I use the following fix locally to avoid the NPE. Not sure it is the correct one though

     private BigDecimal maxOf(BigDecimal max, final BigDecimal summaryMax) {
-        return max != null ? max.max(summaryMax) : summaryMax;
+        return max != null
+            ? summaryMax != null
+                ? max.max(summaryMax)
+                : max
+            : BigDecimal.ZERO;
     }

     private BigDecimal minOf(BigDecimal min, final BigDecimal summaryMin) {
-        return min != null ? min.min(summaryMin) : summaryMin;
+        return min != null
+            ? summaryMin != null
+                ? min.min(summaryMin)
+                : min
+            : BigDecimal.ZERO;
     }

@danhaywood
Copy link
Contributor Author

danhaywood:

possibly not; what if every value is null? The result ought to be null,
but I think this code might give BigDecimal.ZERO.

On 9 October 2014 09:02, Martin Grigorov notifications@github.com wrote:

I use the following fix locally to avoid the NPE. Not sure it is the
correct one though

 private BigDecimal maxOf(BigDecimal max, final BigDecimal summaryMax) {-        return max != null ? max.max(summaryMax) : summaryMax;+        return max != null+            ? summaryMax != null+                ? max.max(summaryMax)+                : max+            : BigDecimal.ZERO;
 }

 private BigDecimal minOf(BigDecimal min, final BigDecimal summaryMin) {-        return min != null ? min.min(summaryMin) : summaryMin;+        return min != null+            ? summaryMin != null+                ? min.min(summaryMin)+                : min+            : BigDecimal.ZERO;
 }


Reply to this email directly or view it on GitHub
isisaddons-legacy/isis-wicket-wickedcharts#2 (comment)
.

@danhaywood
Copy link
Contributor Author

martin-g:

returning null instead of BigDecimal.ZERO seems to do the job as well

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
incode-platform (project)
  
Backlog - Bugs
Development

No branches or pull requests

1 participant