Skip to content

[FormEditor] addPage adds duplicate entries to the 'pages' vector #4107

@2wendex2

Description

@2wendex2

Bug Description

When adding an IFormPage to a FormEditor using the addPage(IFormPage) method, the internal pages vector gets corrupted/duplicated. Both the raw Control (or null for lazy pages) and the IFormPage instance are registered for the same tab. This causes the pages vector indices to become out of sync with the CTabFolder indices.

Steps to Reproduce

  1. Create a custom editor extending FormEditor.
  2. In the addPages() method, call addPage(someFormPage).
  3. Inspect the pages vector after initialization (or observe unexpected behavior in methods relying on pages.get(index) like pageChange, removePage, etc.).

Root Cause

The issue is caused by an unintended polymorphic call chain:

  1. FormEditor.addPage(IFormPage page) calls super.addPage(page.getPartControl()).
  2. MultiPageEditorPart.addPage(Control control) internally calls addPage(getPageCount(), control).
  3. Because FormEditor overrides addPage(int index, Control control), the JVM dispatches the call to FormEditor.addPage(int, Control) instead of the super implementation.
  4. FormEditor.addPage(int, Control) executes registerPage(index, control), adding the Control (or null) to the pages vector.
  5. After the super call returns, FormEditor.addPage(IFormPage) proceeds to call configurePage(i, page).
  6. configurePage calls registerPage(i, page) again, adding the IFormPage to the pages vector.

As a result, two objects are added to the pages vector for a single tab, breaking the 1:1 mapping between the CTabFolder index and the pages vector index.

Expected Behavior

The pages vector should contain exactly one entry per tab (the IFormPage instance). The raw Control should not be registered separately when an IFormPage is added.

Suggested Fix

FormEditor.addPage(IFormPage) should bypass the overridden addPage(int, Control) method and directly call super.addPage(int, Control), or the logic in FormEditor.addPage(int, Control) should check if the control belongs to an IFormPage before registering it.

For example, in FormEditor:

public int addPage(IFormPage page) throws PartInitException {
    int i = getPageCount();
    // Bypass FormEditor.addPage(int, Control) to avoid double registration
    super.addPage(i, page.getPartControl()); 
    configurePage(i, page);
    return i;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions