haiwan / Exporter

A Vaadin Add-on which exports data (in container) to an excel file
Other
8 stars 31 forks source link

NPE in FileBuilder class #17

Open RemusSino opened 7 years ago

RemusSino commented 7 years ago

In Exporter there is the constructor with one argument - Container container. This calls the constructor with two arguments - Container container, Object[] visibleColumns , with null value for visibleColumns. In this constructor, the call this.setContainerToBeExported(container) , eventually creates the FileBuilder and ends up in the setContainer(container) method which also set's the visibleColumns. Then in the same constructor you set again the visibleColumns, to null this time, because it is the value passed in as parameter. This leads to NPE in FileBuilder in methods like buildColumnHeaders, where you check the length on the visibleColumns array which is in fact null - if (this.visibleColumns.length != 0) .

My solution:

    public Exporter(Container container, Object[] visibleColumns) {
        this();
        this.setCaption("Exporter");
//set visible columns first
        this.setVisibleColumns(visibleColumns);
//then, the container
        this.setContainerToBeExported(container);
    }