RFR: 6286501: JTabbedPane throws NPE from its stateChanged listener in particular case
Prasanta Sadhukhan
psadhukhan at openjdk.org
Thu Sep 15 12:31:46 UTC 2022
On Thu, 15 Sep 2022 12:20:51 GMT, Jayathirth D V <jdv at openjdk.org> wrote:
>> Basically, when a tab index is selected via `tbp.setSelectedIndex()` in testcase, it fires a state change event (via `DefaultSingleSelectionModel#setSelectedIndex`) which is caught by the application and in this case, state change listener in the testcase calls `JTabbedPane.updateUI() `which calls `JComponent.setUI() `which first uninstalls UI (which made `tabPane null` in `BasicTabbedPaneUI#uninstallUI`) and then install new UI instance but when it goes to JDK's stateChange listener `BasicTabbedPaneUI.stateChanged()` it passes the new instance but scrollableTabLayoutEnabled() still uses old UI instance in which tabPane is already made null so NPE happens, so it is better to use the tabPane instance passed to UI's stateChange listener..
>
> When we install new UI instance will we not call BasicTabbedPaneUI.installUI() to update current tabPane object? or is it happening at later stage(like after BasicTabbedPaneUI.stateChanged() is called)?
installUI is called for new UI instance with current tabpane object but scrollableTabLayoutEnabled was using the old UI instance whose tabpane object is already reset to null.
-------------
PR: https://git.openjdk.org/jdk/pull/10216
More information about the client-libs-dev
mailing list