Skip to content

Prevent NPE in ToolTipManager#621

Merged
vlsi merged 1 commit intoapache:masterfrom
weisJ:tooltiptext
Sep 16, 2020
Merged

Prevent NPE in ToolTipManager#621
vlsi merged 1 commit intoapache:masterfrom
weisJ:tooltiptext

Conversation

@weisJ
Copy link
Contributor

@weisJ weisJ commented Sep 16, 2020

Description

Return an empty string instead of null in #getToolTipText(MouseEvent) for main frame tree.

Motivation and Context

Even though the documentation for JTree#getToolTipText(MouseEvent) says to return null if the event is null this violates an assumed invariant of the JDK 8 implementation of ToolTipManager.

Generally the ToolTipManager assumes that JComponent#getToolTipText(MouseEvent) always returns a non-null value. For components that simply return the value provided by JComponent#setToolTipText(String) this is always the case. Setting the tooltip to a null/non-null value unregisters or registers the component with the ToolTipManager respectively. For components such as trees where the tooltip text may depend on the current mouse location inside the component this invariant doesn't hold up (because the tree is registered through calling tree.setToolTipText("")).

In some scenarios this can cause a NullPointerException to be thrown in ToolTipManager#initiateToolTip specifically at the following location

 if (!sameComponent || !toolTipText.equals(newToolTipText) || !sameLoc) // Line 478

This bug (JDK-6219960) has been fixed in newer version of the JDK by switching to

Objects.equals(toolTipText, newToolTipText)

but this was never backported to JDK 8.

How Has This Been Tested?

Returning "" has the same semantics as returning null and will result in no tooltip being shown.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants