#1115 Compiler errors when compiling "jfreechart" source

1.0.x
open
nobody
None
5
2013-11-21
2013-07-31
David Tonhofer
No

In ChartFactory.createPieChart()

Ligne 381:

            if (showDifference) {
                series.setValue(key + " (+100%)", newValue);
            }

"series may be null at this location"

Ligne 433:

            if (showDifference) {
                series.setValue(key + " (" + (percentChange >= 0 ? "+" : "")
                        + NumberFormat.getPercentInstance().format(
                        percentChange / 100.0) + ")", newValue);
            }

"series may be null at this location"

Ligne 499:

            if (showDifference) {
                series.setValue(key + " (+100%)", newValue);
            }

"series may be null at this location"

Ligne 557:

            if (showDifference) {
                series.setValue(key + " (" + (percentChange >= 0 ? "+" : "")
                        + NumberFormat.getPercentInstance().format(
                        percentChange / 100.0) + ")", newValue);
            }

"series may be null at this location"

In JFreeChart.draw()

Ligne 1203 & 1214:

            if (e != null) {
                 entities.addAll(e);
            }

"entities may be null at this location"

There are quite a few others of "X may be null at this location". In some cases one can safely tell the compiler using

assert x != null;

the the value is sure to be non-null because an exhaustive if-then was traversed (but the else was missing).

In other cases, I'm not so sure that a NullPointerException won't occur from time to time.

Discussion

  • David Gilbert
    David Gilbert
    2013-11-21

    I've fixed the ones you mentioned, for the upcoming 1.0.17 release. There are more (as you also mentioned), hopefully I'll get to them.