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
- Create a custom editor extending
FormEditor.
- In the
addPages() method, call addPage(someFormPage).
- 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:
FormEditor.addPage(IFormPage page) calls super.addPage(page.getPartControl()).
MultiPageEditorPart.addPage(Control control) internally calls addPage(getPageCount(), control).
- Because
FormEditor overrides addPage(int index, Control control), the JVM dispatches the call to FormEditor.addPage(int, Control) instead of the super implementation.
FormEditor.addPage(int, Control) executes registerPage(index, control), adding the Control (or null) to the pages vector.
- After the super call returns,
FormEditor.addPage(IFormPage) proceeds to call configurePage(i, page).
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;
}
Bug Description
When adding an
IFormPageto aFormEditorusing theaddPage(IFormPage)method, the internalpagesvector gets corrupted/duplicated. Both the rawControl(ornullfor lazy pages) and theIFormPageinstance are registered for the same tab. This causes thepagesvector indices to become out of sync with theCTabFolderindices.Steps to Reproduce
FormEditor.addPages()method, calladdPage(someFormPage).pagesvector after initialization (or observe unexpected behavior in methods relying onpages.get(index)likepageChange,removePage, etc.).Root Cause
The issue is caused by an unintended polymorphic call chain:
FormEditor.addPage(IFormPage page)callssuper.addPage(page.getPartControl()).MultiPageEditorPart.addPage(Control control)internally callsaddPage(getPageCount(), control).FormEditoroverridesaddPage(int index, Control control), the JVM dispatches the call toFormEditor.addPage(int, Control)instead of the super implementation.FormEditor.addPage(int, Control)executesregisterPage(index, control), adding theControl(ornull) to thepagesvector.FormEditor.addPage(IFormPage)proceeds to callconfigurePage(i, page).configurePagecallsregisterPage(i, page)again, adding theIFormPageto thepagesvector.As a result, two objects are added to the
pagesvector for a single tab, breaking the 1:1 mapping between theCTabFolderindex and thepagesvector index.Expected Behavior
The
pagesvector should contain exactly one entry per tab (theIFormPageinstance). The rawControlshould not be registered separately when anIFormPageis added.Suggested Fix
FormEditor.addPage(IFormPage)should bypass the overriddenaddPage(int, Control)method and directly callsuper.addPage(int, Control), or the logic inFormEditor.addPage(int, Control)should check if the control belongs to anIFormPagebefore registering it.For example, in
FormEditor: