title: Modifying children in a org.eclipse.ui.forms.widgets.Section causes exception
body: <p>I have a problem that I am facing with using <code>org.eclipse.ui.forms.widgets.Section</code>, that if I add children to it and modify the children by enabling them or setting text on them I get an exception. I have written a small snippet to easily reproduce the problem below:</p>
  
  <pre class="lang-java prettyprint-override"><code>import org.eclipse.jface.dialogs.MessageDialog;
  import org.eclipse.swt.SWT;
  import org.eclipse.swt.events.SelectionAdapter;
  import org.eclipse.swt.events.SelectionEvent;
  import org.eclipse.swt.layout.GridData;
  import org.eclipse.swt.layout.GridLayout;
  import org.eclipse.swt.widgets.Button;
  import org.eclipse.swt.widgets.Composite;
  import org.eclipse.swt.widgets.Display;
  import org.eclipse.swt.widgets.Shell;
  import org.eclipse.ui.forms.widgets.Section;
  
  public class SectionTest {
      /**
       * @param args
       */
      public static void main(String[] args) {
          final Display display = new Display ();
          final Shell shell = new Shell (display);
          shell.setLayout(new GridLayout());
  
          Button b = new Button(shell, SWT.PUSH);
          b.addSelectionListener(new SelectionAdapter() {
              @Override
              public void widgetSelected(SelectionEvent e) {
                  addSection(shell);
              }
          });
          b.setText("Add");
  
          addSection(shell);
  
          shell.setSize(300, 300);
          shell.open();
          while (!shell.isDisposed()) {
              try {
                  if (!display.readAndDispatch())
                      display.sleep();
              }
              catch (Exception e) {
                  e.printStackTrace();
                  MessageDialog.openError(shell, "Error", e.getMessage());
              }
          }
          display.dispose();
      }
  
      private static void addSection(Composite parent) {
          Section section = new Section(parent, Section.TITLE_BAR | Section.TREE_NODE | Section.CLIENT_INDENT);
          section.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
          section.setText("Hello");
          //section.setSize(1, 1);
  
          // Add the check button for enabling/disabling this group
          Button enableControl = new Button(section, SWT.CHECK);
          enableControl.setText("Enable");
          section.setTextClient(enableControl);
  
          Composite client = new Composite(section, SWT.NONE);
          section.setClient(client);
          client.setLayout(new GridLayout());
  
          Button b = new Button(client, SWT.PUSH);
          b.setText("one");
  
          b = new Button(client, SWT.PUSH);
          b.setText("two");
          parent.layout();
      }
  }
  </code></pre>
  
  <p>If you run the code a dialog will appear with an add button. Clicking on the add button will produce the exception.</p>
  
  <p>Exception text:</p>
  
  <pre><code>java.lang.IllegalArgumentException: Argument not valid
      at org.eclipse.swt.SWT.error(SWT.java:4342)
      at org.eclipse.swt.SWT.error(SWT.java:4276)
      at org.eclipse.swt.SWT.error(SWT.java:4247)
      at org.eclipse.swt.graphics.Image.init(Image.java:1558)
      at org.eclipse.swt.graphics.Image.&lt;init&gt;(Image.java:181)
      at org.eclipse.ui.forms.widgets.Section.onPaint(Section.java:344)
      at org.eclipse.ui.forms.widgets.ExpandableComposite$1.paintControl(ExpandableComposite.java:560)
      at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:230)
      at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
      at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
      at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1077)
      at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1062)
      at org.eclipse.swt.widgets.Composite.WM_PRINTCLIENT(Composite.java:1639)
      at org.eclipse.swt.widgets.Control.windowProc(Control.java:4590)
      at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:341)
      at org.eclipse.swt.widgets.Display.windowProc(Display.java:4976)
      at org.eclipse.swt.internal.win32.OS.CallWindowProcW(Native Method)
      at org.eclipse.swt.internal.win32.OS.CallWindowProc(OS.java:2440)
      at org.eclipse.swt.widgets.Button.callWindowProc(Button.java:343)
      at org.eclipse.swt.widgets.Control.windowProc(Control.java:4623)
      at org.eclipse.swt.widgets.Display.windowProc(Display.java:4976)
      at org.eclipse.swt.internal.win32.OS.SetWindowTextW(Native Method)
      at org.eclipse.swt.internal.win32.OS.SetWindowText(OS.java:3461)
      at org.eclipse.swt.widgets.Button._setText(Button.java:300)
      at org.eclipse.swt.widgets.Button.setText(Button.java:1099)
      at org.eclipse.swt.snippets.SectionTest.addSection(SectionTest.java:58)
      at org.eclipse.swt.snippets.SectionTest.access$0(SectionTest.java:50)
      at org.eclipse.swt.snippets.SectionTest$1.widgetSelected(SectionTest.java:28)
      at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:248)
      at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
      at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
      at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4169)
      at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3758)
      at org.eclipse.swt.snippets.SectionTest.main(SectionTest.java:39)
  </code></pre>
  
  <p>This problem occurs with 32-bit JRE (and eclipse) on a Windows 7 64-bit machine. This same problem is not reproducible on Windows XP (32-bit).</p>
  
  <p>My question is, what I am doing wrong that causes this exception. If you notice I add a section using the same method before the shell opens and it runs without any problems, however once the shell is open and visible calling the same <code>addSection(Composite)</code> method causes exceptions.</p>
  
  <blockquote>
    <p><strong>NOTE</strong>: Uncommenting the line 'section.setSize(1, 1);' in <code>addSection(Composite)</code> will "hide" the problem, but it does not seem like the right thing to do. What is correct way to use Sections?</p>
  </blockquote>
  
  <hr>
  
  <blockquote>
    <p><strong>Edit:</strong> Found an issue already reported in ecilpse, <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=309443" rel="nofollow">https://bugs.eclipse.org/bugs/show_bug.cgi?id=309443</a>, which seems to be the same finding as this question.</p>
  </blockquote>