aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/main/java/com/vaadin/tests/layouts/GridLayoutNPE.java
blob: 794ecf1d38c17ff959afb9e43fce94438e77c204 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package com.vaadin.tests.layouts;

import com.vaadin.tests.components.TestBase;
import com.vaadin.ui.Button;
import com.vaadin.ui.GridLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.VerticalLayout;

public class GridLayoutNPE extends TestBase {

    @Override
    protected void setup() {
        final VerticalLayout lo = new VerticalLayout();

        final GridLayout gl = new GridLayout(2, 1);
        gl.setSpacing(true);

        final Label toRemove = new Label("First");
        gl.addComponent(toRemove);
        final Label toEdit = new Label("Second");
        gl.addComponent(toEdit);

        final Button b = new Button("remove 'First'");
        final Button b2 = new Button("edit 'Second'");
        b2.setVisible(false);

        lo.addComponent(gl);
        lo.addComponent(b);
        lo.addComponent(b2);

        b.addClickListener(event -> {
            gl.removeComponent(toRemove);

            // move another component to where the first was removed
            // before rendering to the client
            gl.removeComponent(toEdit);
            // this could also be the result of removeAllComponents()
            // followed by a loop of addComponent(c)
            gl.addComponent(toEdit, 0, 0);

            b.setVisible(false);
            b2.setVisible(true);
        });

        b2.addClickListener(event -> toEdit.setValue("Second (edited)"));

        addComponent(lo);
    }

    @Override
    protected String getDescription() {
        return "VGridLayout throws an NPE, causing client side to crash";
    }

    @Override
    protected Integer getTicketNumber() {
        return 4019;
    }

}