Skip to content

BoxChart rejects valid List.of data with NullPointerException #1032

Closed

Description

@PHJ2000

Describe the bug
BoxChart rejects valid, null-free lists created with List.of(...). Both adding a series and replacing its data throw NullPointerException because the validation calls contains(null), which these lists do not support.

To Reproduce

import java.util.List;
import org.knowm.xchart.BoxChart;
import org.knowm.xchart.BoxChartBuilder;
import org.knowm.xchart.SwingWrapper;

public class ImmutableBoxData {
  public static void main(String[] args) {
    new SwingWrapper<>(getChart()).displayChart();
  }

  public static BoxChart getChart() {
    BoxChart chart = new BoxChartBuilder().width(640).height(480).build();
    chart.addSeries("sample", List.of(1, 2, 3)); // NullPointerException
    return chart;
  }
}

The same exception occurs when calling series.replaceData(List.of(4, 5)) or chart.updateBoxSeries(...) on an existing series.

Expected behavior
Accept the null-free lists while continuing to reject lists that actually contain null elements.

Reproduced on 4.0.5-SNAPSHOT, Java 11. The exception happens before rendering, so no screenshot is needed. Tests cover two- and three-element immutable lists, replacement/update, and rejection of actual null elements.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions