JDK-8204856 : WebEngine document becomes null after PAGE_REPLACED event
  • Type: Bug
  • Component: javafx
  • Sub-Component: web
  • Affected Version: 8u171,9,10,openjfx11
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: x86_64
  • Submitted: 2018-06-07
  • Updated: 2020-01-31
  • Resolved: 2018-07-05
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 8 Other
8u191Fixed openjfx11Fixed
Related Reports
Relates :  
Description
A DESCRIPTION OF THE PROBLEM :
the document of the WebEngine return nulls after the PAGE_REPLACED event. Probably because the PAGE_REPLACED events set the boolean invalidate to false which causes the getDocument to always return null. 

REGRESSION : Last worked in version 8u162

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Load the following url in the WebEngine https://movies-finder.firebaseapp.com/ 
After clicking on one of the menu items ( which triggers the PAGE_REPLACED event), 
The document of the webEngine returns null


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The document of the webEngine is the same as Document e = (Document) engine.executeScript("document");
ACTUAL -
The document of the webEngine is null

---------- BEGIN SOURCE ----------
import javax.swing.JFrame;

import org.w3c.dom.Document;

import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.embed.swing.JFXPanel;
import javafx.scene.Scene;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;

public class TestCase_001 {
	public static void main(String[] args) {
		Platform.setImplicitExit(false);

		JFrame frame = new JFrame("JFXTest");
		frame.setSize(1400, 1000);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		JFXPanel jfxPanel = new JFXPanel();

		Platform.runLater(() -> {
			WebView webView = new WebView();
			final WebEngine engine = webView.getEngine();
			engine.load("https://movies-finder.firebaseapp.com/");
			engine.documentProperty().addListener(new ChangeListener<Document>() {
				@Override
				public void changed(ObservableValue<? extends Document> prop, Document oldDoc, Document newDoc) {
					System.out.println("old document " + oldDoc);
					System.out.println("new document " + newDoc);

					Document e = (Document) engine.executeScript("document");
					Document e2 = engine.getDocument();
					System.out.println("document from script " + e);
					System.out.println("document from engine " + e2);
				}
			});
			Scene scene = new Scene(webView);
			jfxPanel.setScene(scene);
		});

		frame.add(jfxPanel);
		frame.setVisible(true);
	}
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
 Object obj = engine.documentProperty();
            System.out.println(Arrays.toString(obj.getClass().getDeclaredMethods()));
            Method method = obj.getClass().getDeclaredMethod("invalidate",Boolean.TYPE);
            if (method!=null){
                method.setAccessible(true);
                method.invoke(obj, true);
            }

FREQUENCY : always



Comments
changeset: 01a04d558b99 user: arajkumar date: Thu Jul 05 12:12:27 2018 +0530 summary: 8204856: WebEngine document becomes null after PAGE_REPLACED event URL: http://hg.openjdk.java.net/openjfx/jfx-dev/rt/rev/01a04d558b99
05-07-2018

+1
03-07-2018

Test cases fail without fix and passes with fix. +1 nit: you can update copyright year.
28-06-2018

patch: http://cr.openjdk.java.net/~arajkumar/8204856/webrev Root cause: When ever location changes due WebHistory API calls, we propagate it to WebEngine to update the `location` property. However the private method{WebEngine.updateLocation} which we used to update `location` also invalidates the `document` property of WebEngine, which is undesirable. Solution: Directly update the `location` property when WebEngine gets PAGE_REPLACED event. Don���t use {WebEngine.updateLocation}. Testing: Unit tests are added to cover both history.pushState and history.replaceState., Use the following command to run the newly added unit test, ``` gradle :web:cleanTest :web:test --tests test.javafx.scene.web.HistoryStateTest ``` (Note: No _need_ to compile the web module in order to test this fix, all changes are done only in Java binding files)
27-06-2018

This is a regression of JDK-8157686.
26-06-2018

Issue is reproducible in 8u171-b01 and not in 8u162-b12. When ran the provided test case with 8u171-b01 and clicked on 'upcoming movies' menu item, engine.getDocument() returns null unlike with 8u162. Logs from test case, after clicking menu item for 8u171: old document [object HTMLDocument] new document null document from script [object HTMLDocument] document from engine null Windows 10, 64-bit JDK results ---------------------------------- 8u162-b12 : Pass 8u171-b01 : Fail <=Regression 8u171-b11 : Fail 10.0.1+10 : Fail 11-ea+13 : Fail
12-06-2018