container.removeAllItems causing java.lang.IllegalStateException: A connect


I have a Vaadin application that requests the data from the backhand application and then puts the returned data in the BeanItemContainer. That BeanItemContainer is then set as a container data source for a table. My application requires the table/data sorting to be done in the backhand application. To achieve this I’ve overriden paintContent method which is getting called if the user clicks on one of the table headers. When this happens Vaadin applications makes a request for updated/sorted data from the backhand application and tries to update the container by first removing all the data and then adding the new data. However, everytime I call the
container.removeAllItems() I get an java.lang.IllegalStateException: A connector should not be marked as dirty while a response is being written

NOTE: There are no background threads involved in this application.

I don’t really understand what’s happening here. I couldn’t find much documentation on paintContent. My guess is that when we enter paintContent the dirty flag is set to true and it is not marked as clean until we exit the paintContent method. While the flag is marked as dirty, manipulating container data is not allowed. It apperas that call to container.removeAllItems tries to mark it as dirty while the flag already marked as dirty, causing the exception to be thrown. Is this the case? Am I not allowed to do any container data manipulation from within painContent? Is there any way around it?

I’ve also noticed that other operations on table, such as setColumnHeader, would cause the execption.

Here’s a simplified version of the code:

public void paintContent(PaintTarget target) throws PaintException {
    Object[] expanded_columns = getCurrentVisibleColumns();
    Object cur_sort_id = getSortContainerPropertyId();
    boolean cur_sort_ascending = isSortAscending();

    if (visible_columns.length != expanded_columns.length) {
        visible_columns = expanded_columns;
    if (sort_id != cur_sort_id) {
        sort_id = cur_sort_id;
    if (sort_ascending != cur_sort_ascending) {
        sort_ascending = cur_sort_ascending;

public void private sortChange() {
// update the table with new sorted data
// .... some code here ...
// .... some code here ...

protected void updatePage() {
    try {
container_current.removeAllItems(); // exception thrown here
    } finally {