Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 330224 - Grid.setColumnOrder() throws SWT.ERROR_INVALID_ARGUMENT if first column is column group with a single column
Summary: Grid.setColumnOrder() throws SWT.ERROR_INVALID_ARGUMENT if first column is co...
Status: CLOSED INVALID
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Nebula (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Thomas Schindl CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-11-15 06:26 EST by Bilal Alsallakh CLA
Modified: 2021-07-05 11:40 EDT (History)
1 user (show)

See Also:


Attachments
The code Grid.java including the bug fix (341.37 KB, application/octet-stream)
2010-11-22 04:00 EST, Bilal Alsallakh CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Bilal Alsallakh CLA 2010-11-15 06:26:53 EST
Build Identifier: M20090917-0800

The fix introduced in Bug# 290547 solves half of the problem, here i will explain the remaining half:

A grid has five colulmns and three column groups.
The first ColumnGroup contains the first column only. The second group contains the next 3 columns, and the 3rd group contains the last column.

The current code causes an SWT error:

            for (int i = 0; i < order.length; i++)
            {
                GridColumn col = getColumn(order[i]);

                if (currentGroup != null)
                {

                    if (col.getColumnGroup() != currentGroup && colsInGroup > 0 )
                    {
                        SWT.error(SWT.ERROR_INVALID_ARGUMENT);
                    }
                    else
                    {
                        colsInGroup--;
                        if (colsInGroup <= 0)
                        {
                            currentGroup = null;
                        }
                    }
                }
                else if (col.getColumnGroup() != null)
                {
                    currentGroup = col.getColumnGroup();
                    colsInGroup = currentGroup.getColumns().length - 1;
                }
            }
        }

Analysis:

After the first iteration, currentGroup is set to the 1st group, colsInGroup is set to 0.
After the 2nd iteration, currentGroup is set to null, colsInGroup is set to -1.
After the 3rd iteration, currentGroup is set to 2ndGroup. colsInGroup is set to 2 (which is wrong since we are already in the 2nd column in the current group..).
After the 4rd iteration, currentGroup is set to 2ndGroup. colsInGroup is set to 1
In the fifth iteration -> crash (since we have a new group but colsInGroup is still > 0).


patch:

            for (int i = 0; i < order.length; i++)
            {
                GridColumn col = getColumn(order[i]);

                if (currentGroup != null)
                {
                    if (col.getColumnGroup() != currentGroup)
                    {
                        if (colsInGroup > 0 )
                        {
                            SWT.error(SWT.ERROR_INVALID_ARGUMENT);
                        }
                        else
                        {
                            currentGroup = col.getColumnGroup();
                            if (currentGroup != null) {
                                colsInGroup = currentGroup.getColumns().length - 1;
                            }
                        }
                    }
                    else
                    {
                        colsInGroup--;
                        if (colsInGroup <= 0)
                        {
                            currentGroup = null;
                        }
                    }
                }
                else if (col.getColumnGroup() != null)
                {
                    currentGroup = col.getColumnGroup();
                    colsInGroup = currentGroup.getColumns().length - 1;
                }
            }
        }


Reproducible: Always

Steps to Reproduce:
create a group with five colulmns and three column groups.
The first ColumnGroup contains the first column only. The second group contains the next 3 columns, and the 3rd group contains the last column.
Comment 1 Bilal Alsallakh CLA 2010-11-22 04:00:08 EST
Created attachment 183554 [details]
The code Grid.java including the bug fix
Comment 2 Wim Jongman CLA 2019-12-12 15:58:08 EST
This bug does not have a target milestone assigned and is automatically closed as part of the 2.3.0 release cleanup.

It could be that this bug is accidentally closed for which we apologize.

If this bug is still relevant, please re-open and set a target milestone.