OpenJFX 9-dev XYChart.java ......这是一个错误吗?

时间:2015-03-31 21:15:52

标签: java javafx nullpointerexception

我最近一直在浏览与JavaFX图表相关的源代码,我遇到了以下方法:

/**
 * This should be called from seriesRemoved() when you are finished with any animation for deleting the series from
 * the chart. It will remove the series from showing up in the Iterator returned by getDisplayedSeriesIterator().
 *
 * @param series The series to remove
 */
protected final void removeSeriesFromDisplay(Series<X, Y> series) {
    if (series != null) series.setToRemove = false;
    series.setChart(null);
    displayedSeries.remove(series);
}

此处:http://hg.openjdk.java.net/openjfx/9-dev/rt/file/9c2e8ff4fa26/modules/controls/src/main/java/javafx/scene/chart/XYChart.java#l910

如果传入的系列为空,则无需进行调用series.setChart(null);,如果系列为空,则会导致NullPointerException。鉴于该方法受到保护并因此对子类可见,if语句是否应该包含围绕整个方法的括号?基本上:

/**
 * This should be called from seriesRemoved() when you are finished with any animation for deleting the series from
 * the chart. It will remove the series from showing up in the Iterator returned by getDisplayedSeriesIterator().
 *
 * @param series The series to remove
 */
protected final void removeSeriesFromDisplay(Series<X, Y> series) {
    if (series != null) {
        series.setToRemove = false;
        series.setChart(null);
    }
    displayedSeries.remove(series);
}

鉴于OpenJFX作者比我更好的程序员,我犹豫是否将此报告为一个错误,特别是考虑到我没有设置这样做(通过他们的JIRA系统或他们的邮件列表,我想问一下在我让自己难堪之前,比我更有知识渊博的人!)

0 个答案:

没有答案