JDK-8190349 : Tooltip based on graphic contented only show less than 1 out of 10 times
  • Type: Bug
  • Component: javafx
  • Sub-Component: web
  • Affected Version: 9,10
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2017-10-18
  • Updated: 2018-12-03
  • Resolved: 2017-11-09
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 10
10Fixed
Related Reports
Duplicate :  
Duplicate :  
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :
java 9
Java(TM) SE Runtime Environment (build 9+181)
Java HotSpot(TM) 64-Bit Server VM (build 9+181, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Windows 10.0.15063 (10 Pro 64-bit)

EXTRA RELEVANT SYSTEM CONFIGURATION :
NVidia GForce GT 730

A DESCRIPTION OF THE PROBLEM :
Tooltips with graphic contect only show up black without any content being shown with the exception of maybe the first tooltip that you pop-up) in Java 9.

This wasn't an issue with any of the Java 8 runtime engines that were released for at least the passed year.

REGRESSION.  Last worked in version 8u144

ADDITIONAL REGRESSION INFORMATION: 
I don't have Java 8 installed anymore, but was 8 Update 144, and all the versions before it in the passed year or so. In all those versions I never had any problem when using setGraphic straight instead of having to use a workaround (see below)

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Put a WebTooltip (see class below) on a few JavaFX controls (no CSS, just the CSS defaults for a .tooltip already trigger this).
Usually when hovering over the first control, you see the tooltip pop-up as expected, but thereafter on a second or 3 control it goes wrong consistently.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Expectation: Tooltips should always show.
ACTUAL -
Tooltips show up black without any content, with a possible exception of the first tooltip that you are trying to see.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.concurrent.Worker;
import javafx.concurrent.Worker.State;
import javafx.event.EventHandler;
import javafx.scene.CacheHint;
import javafx.scene.control.ContentDisplay;
import javafx.scene.control.Tooltip;
import javafx.scene.text.FontSmoothingType;
import javafx.scene.web.WebView;
import javafx.stage.WindowEvent;
import javafx.util.Duration;

public class WebTooltip extends Tooltip {
	
	//Only create WebToolTip on demand using MouseListener and discard after being shown. Underlying JavaFX WebView control burns memory 
    //continuously, even when Tooltip is not visible (a couple of hundred of these will result in 5..10MB heap-space being claimed). This 
	//results in high CPU load, and frequent garbage collections that also generate large spikes due to the number of objects that need 
    //freeing (180 ->80MB free if System.gc() is run every 10 seconds):
	public WebTooltip(String text) {
		setShowDuration(new Duration(30000)); //unit is ms
		final WebView webView = new WebView();
		webView.setPrefSize(1024, -1);
		webView.setFontSmoothingType(FontSmoothingType.GRAY);
		//webView.setDisable(true);
		webView.setMouseTransparent(true);
		webView.setCache(true);
		webView.setCacheHint(CacheHint.QUALITY);
		webView.getEngine().loadContent("<html><head><style>td {white-space: nowrap;} body white-space: nowrap; overflow-x: hidden; overflow-y: hidden;}</style></head><body><div id='mydiv' style='overflow:hidden'>" + text + "</div></body></html>"); //This does not immediately trigger the above changed handler
		//webView.getEngine().loadContent("<html><head></head><body><div id='mydiv'>testText</div></body></html>"); //This does not immediately trigger the above changed handler
		//Switch this label over to display it's content as graphic only: The graphic will be provided by the WebView component:
		webView.getEngine().getLoadWorker().stateProperty().addListener(new ChangeListener<State>() {
			@Override
			public void changed(ObservableValue<? extends State> ov, State oldState, State newState) {
				if (newState == Worker.State.SUCCEEDED) { //This adjustsize has different 'margins' then the one in WebLabel!
					Object result = webView.getEngine().executeScript("document.getElementById('mydiv').offsetHeight");
					if (result instanceof Integer)  
						webView.setPrefHeight((Integer)result+15);
					// offsetWidth can not be used for the next command in WebKit, but scrollWidth seems to do the trick:
					result = webView.getEngine().executeScript("document.getElementById('mydiv').scrollWidth");
					if (result instanceof Integer)  
						webView.setPrefWidth((Integer)result + 25);
				}
			}
		});
		setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
  		setGraphic(webView);
	}
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Change the setGraphic() line to:
		setOnShown(new EventHandler<WindowEvent>(){
		      @Override
		      public void handle(WindowEvent arg0) {
		  		setGraphic(webView);
		      }
		    });
Now the tootlips show 100% of the time again.


Comments
Changeset: 806b73c56481 Author: mbilla Date: 2017-11-09 13:23 +0530 URL: http://hg.openjdk.java.net/openjfx/10-dev/rt/rev/806b73c56481
09-11-2017

+1
09-11-2017

Since this reverts the logic back to what it is on JDK 8 (and was in JDK 9 prior to JDK-8090322), this seems like a safe and correct fix to me. +1
06-11-2017

webrev: http://cr.openjdk.java.net/~mbilla/8190349/webrev.00/ Reverted the changes done for WebView.java as part of JDK-8090322.
06-11-2017

More analysis is needed, but this seems to be another place that should not have been changed as part of the fix for JDK-8090322, so reverting this part of the fix, as shown above, it is likely the right thing to do.
03-11-2017

I could not pin-point the cause of regression. Here are the observations : 1) Issue is not reproducible with normal Tooltips on JDK8, JDK9 and JDK10. 2) Issue is reproducible ONLY with custom Tooltips containing WebView on JDK9 and JDK10 (refer to the attached test) - Dedicated graphics card is not needed to reproduce the issue. I could see this happening on Windows7 with on-board Intel graphics card. - I saw a different behavior than what is reported - for me, first tooltip in test application is shown blank and subsequent tooltips are shown correctly - (the bug is reported as first tooltip is shown correctly and subsequent tooltips are blank)
31-10-2017

Checked test case (PFA ToolTipTest.java) using 9+181 & 10-ea+23, and issue is reproducible. Windows 10 - JDK results ----------------------------------- 8u144 : Pass 8u162-b01 : Pass 9+126 : pass 9+127 : fail <--- regression introduced here 9+181 : Fail 10-ea+23 : Fail PFA screenshot of test case, ran using different JDK versions. (tooltip_screenshots.png)
30-10-2017