vaadin / vaadin/spreadsheet

ArrayIndexOutOfBoundException in Spreadsheet.handleRowSizes when using a ComponentFactory

Open
#669 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
50
Forks
53
Avg merge
1d 21h
Merged PRs (30d)
1

Description

Vaadin version 8.4.5, Spreadsheet 2.1.0.alpha1

Minimal example to reproduce - just click the button.

package foo.bar;

import javax.servlet.annotation.WebServlet;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Sheet;

import com.vaadin.addon.spreadsheet.Spreadsheet;
import com.vaadin.addon.spreadsheet.SpreadsheetComponentFactory;
import com.vaadin.annotations.Theme;

import com.vaadin.annotations.VaadinServletConfiguration;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinServlet;
import com.vaadin.ui.Button;
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.Component;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;

@Theme("mytheme")
public class MyUI extends UI {

    @Override
    protected void init(VaadinRequest vaadinRequest) {
        final VerticalLayout layout = new VerticalLayout();
		Spreadsheet sheet = new Spreadsheet(6, 6);
		sheet.setSpreadsheetComponentFactory(getFactory());
        
		Button b = new Button("New entry");
		b.addClickListener(e -> addRow(sheet));

		layout.addComponent(b);
		layout.addComponent(sheet);
		setContent(layout);

    }

    private SpreadsheetComponentFactory getFactory() {
    	SpreadsheetComponentFactory f = new SpreadsheetComponentFactory() {
			
			@Override
			public void onCustomEditorDisplayed(Cell cell, int rowIndex, int columnIndex, Spreadsheet spreadsheet, Sheet sheet,
					Component customEditor) {
			}
			
			@Override
			public Component getCustomEditorForCell(Cell cell, int rowIndex, int columnIndex, Spreadsheet spreadsheet,
					Sheet sheet) {
				return null;
			}
			
			@Override
			public Component getCustomComponentForCell(Cell cell, int rowIndex, int columnIndex, Spreadsheet spreadsheet,
					Sheet sheet) {
				if((columnIndex==1))
					return new ComboBox();
				else
					return null;
			}
		};
		return f;
	}

	private void addRow(Spreadsheet sheet) {
		int rows = sheet.getRows();
		sheet.shiftRows(1, rows, 1);
		sheet.setMaxRows(rows + 1);
	}

	@WebServlet(urlPatterns = "/*", name = "MyUIServlet", asyncSupported = true)
    @VaadinServletConfiguration(ui = MyUI.class, productionMode = false)
    public static class MyUIServlet extends VaadinServlet {
    }
}

Possibly similar cause as #459 but at a different place in the code.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the minimal example in the issue and reproduce the exception by clicking “New entry” with a SpreadsheetComponentFactory configured. Inspect Spreadsheet.handleRowSizes and compare the related behavior in issue #459. Done means inserting a row no longer raises ArrayIndexOutOfBoundException when a component factory supplies a custom component.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.