Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 330224

Summary: Grid.setColumnOrder() throws SWT.ERROR_INVALID_ARGUMENT if first column is column group with a single column
Product: z_Archived Reporter: Bilal Alsallakh <bilal.alsallakh>
Component: NebulaAssignee: Thomas Schindl <tom.schindl>
Status: CLOSED INVALID QA Contact:
Severity: normal    
Priority: P3 CC: cgross
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
The code Grid.java including the bug fix none

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.