JDK-8182977 : NullPointerException with HTMLEditor when changing the scene graph
  • Type: Bug
  • Component: javafx
  • Sub-Component: web
  • Affected Version: 8,9
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2017-06-24
  • Updated: 2020-01-31
  • Resolved: 2017-08-21
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 JDK 8
10Fixed 8u162Fixed
Description
FULL PRODUCT VERSION :
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
ver 1703

A DESCRIPTION OF THE PROBLEM :
When I change the scene graph and the new root contains a HTMLEditor, then a NullPointerException is thrown.

See the source code of the class "HTMLEditorBug".

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
compile and run the class "HTMLEditorBug"

ACTUAL -
NullPointerException

ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
	at com.sun.javafx.scene.web.skin.HTMLEditorSkin.updateToolbarState(HTMLEditorSkin.java:964)
	at com.sun.javafx.scene.web.skin.HTMLEditorSkin.lambda$populateToolbars$13(HTMLEditorSkin.java:580)
	at com.sun.javafx.binding.ExpressionHelper$Generic.fireValueChangedEvent(ExpressionHelper.java:361)
	at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:81)
	at javafx.beans.property.ObjectPropertyBase.fireValueChangedEvent(ObjectPropertyBase.java:105)
	at javafx.beans.property.ObjectPropertyBase.markInvalid(ObjectPropertyBase.java:112)
	at javafx.beans.property.ObjectPropertyBase.set(ObjectPropertyBase.java:146)
	at javafx.scene.control.ComboBoxBase.setValue(ComboBoxBase.java:150)
	at com.sun.javafx.scene.web.skin.HTMLEditorSkin.lambda$populateToolbars$12(HTMLEditorSkin.java:549)
	at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
	at java.security.AccessController.doPrivileged(Native Method)
	at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
	at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
	at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
	at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
	at java.lang.Thread.run(Unknown Source)

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
package javaBugs;

import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.scene.web.HTMLEditor;
import javafx.stage.Stage;

public class HTMLEditorBug extends Application{

	public static void main(String[] args){
		launch(args);
	}

	@Override
	public void start(Stage primaryStage) throws Exception {
		Label label = new Label("Pane 1");
		StackPane pane1 = new StackPane(label);
		pane1.setPadding(new Insets(10));
		
		Scene scene = new Scene(pane1, 600, 400);
		primaryStage.setScene(scene);
		primaryStage.show();
		
		HTMLEditor editor = new HTMLEditor();
		StackPane pane2 = new StackPane(editor);
		pane2.setPadding(new Insets(10));
		
		scene.setRoot(pane2);
	}
}
---------- END SOURCE ----------


Comments
Changeset: 6eb9d7f349ab Author: mbilla Date: 2017-08-21 18:39 +0530 URL: http://hg.openjdk.java.net/openjfx/10-dev/rt/rev/6eb9d7f349ab
21-08-2017

+1
16-08-2017

+1
16-08-2017

I tried for unit test.. But In this case, i need to show window to repro. the NPE..
16-08-2017

+1, Is it possible to integrate the test as part of unittest(:web:test) instead of system test?
16-08-2017

webrev: http://cr.openjdk.java.net/~mbilla/8182977/webrev.01/ Tested the test case without fix and below error displayed. Test case passed with fix. test.com.sun.javafx.application.SceneGraphHTMLEditorTest > testHTMLEditorSceneGraph FAILED java.lang.RuntimeException: UncaughtException at test.com.sun.javafx.application.SceneGraphHTMLEditorTest.testHTMLEditorSceneGraph(SceneGraphHTMLEditorTest.java:111) Caused by: java.lang.NullPointerException
15-08-2017

I'm not sure this is quite right to just suppress the NPE. The intention seems to be to set the value to sizeFontMap.get(SIZE_SMALL) if it isn't already set to that value. Without looking more closely, it seems reasonable to do this in the case where the value is null. In that case, the following might be a better fix: - if (!fontSizeComboBox.getValue().equals(sizeFontMap.get(SIZE_SMALL))) { + if ((fontSizeComboBox.getValue() == null) || !fontSizeComboBox.getValue().equals(sizeFontMap.get(SIZE_SMALL))) { Also, can you provide a unit test for this?
08-08-2017

webrev: http://cr.openjdk.java.net/~mbilla/8182977/webrev.00/ In this case, fontFamilyComboBox.setValue(""); is called and later we need to check fontFamilyComboBox value before accessing fontSizeComboBox.getValue()
07-08-2017

Issue reproducible in both Windows and Linux. Getting NPE in JDK 8 and 9. JDK results: ======== 8 GA: Fail 8u121 : Fail 8u131 : Fail 9-ea+173 : Fail ========
27-06-2017