RFR: 6286501: JTabbedPane throws NPE from its stateChanged listener in particular case
Jayathirth D V
jdv at openjdk.org
Thu Sep 15 12:22:55 UTC 2022
On Thu, 15 Sep 2022 09:58:59 GMT, Prasanta Sadhukhan <psadhukhan at openjdk.org> wrote:
>> src/java.desktop/share/classes/javax/swing/plaf/basic/BasicTabbedPaneUI.java line 4102:
>>
>>> 4100: setFocusIndex(tabPane.getSelectedIndex(), false);
>>> 4101:
>>> 4102: if (tabPane.getLayout() instanceof TabbedPaneScrollLayout) {
>>
>> I see BasicTabbedPaneUI.tabPane object getting used in other listeners in this Handler class. Is there a reason why only when we hit stateChanged() function we are seeing NPE?
>>
>> Is this NPE for tabPane object itself or Layout not being initialized?
>
> 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)?
-------------
PR: https://git.openjdk.org/jdk/pull/10216
More information about the client-libs-dev
mailing list