JDK-8093938 : [Mac,CSS] NPE in StyleManager: Thread.currentThread().getContextClassLoader() is null
  • Type: Bug
  • Component: javafx
  • Sub-Component: web
  • Affected Version: 8u40
  • Priority: P4
  • Status: Closed
  • Resolution: Cannot Reproduce
  • Submitted: 2015-03-18
  • Updated: 2016-09-02
  • Resolved: 2015-07-31
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 9
9Resolved
Related Reports
Relates :  
Description
There is an NPE on Mac when we try to instantiate a new WebView().
We traced the exception back to "Thread.currentThread().getContextClassLoader()" being null.

NOTE: This only happens when NOT running in sandbox-mode.
IN sandbox mode it seems to work without the workaround (see below).
And the workaround itself would not work in sandbox mode due to security restrictions.

INFO: JFXPanelExt is our own class to wrap all the WebView / WebEngine stuff.
We use only a JFXPanel with a WebView inside a JFrame (not the whole JFX Stage system).

    Exception in thread "AppKit Thread" java.lang.ExceptionInInitializerError
     at com.sun.javafx.webkit.theme.ScrollBarThemeImpl$1.invalidated(ScrollBarThemeImpl.java:108)
     at com.sun.javafx.binding.ExpressionHelper$Generic.fireValueChangedEvent(ExpressionHelper.java:349)
     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.beans.property.ObjectProperty.setValue(ObjectProperty.java:69)
     at javafx.scene.web.WebEngine.setView(WebEngine.java:960)
     at javafx.scene.web.WebView.<init>(WebView.java:272)
     at base.webview.JFXPanelExt$1.run(JFXPanelExt.java:75)
     at com.sun.javafx.application.PlatformImpl.lambda$null$170(PlatformImpl.java:295)
     at com.sun.javafx.application.PlatformImpl$$Lambda$61/1601331386.run(Unknown Source)
     at java.security.AccessController.doPrivileged(Native Method)
     at com.sun.javafx.application.PlatformImpl.lambda$runLater$171(PlatformImpl.java:294)
     at com.sun.javafx.application.PlatformImpl$$Lambda$60/1534821193.run(Unknown Source)
     at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    Caused by: java.lang.NullPointerException
     at com.sun.javafx.css.StyleManager.getURL(StyleManager.java:840)
     at com.sun.javafx.css.StyleManager.loadStylesheetUnPrivileged(StyleManager.java:1029)
     at com.sun.javafx.css.StyleManager.loadStylesheet(StyleManager.java:890)
     at com.sun.javafx.css.StyleManager._setDefaultUserAgentStylesheet(StyleManager.java:1338)
     at com.sun.javafx.css.StyleManager.setUserAgentStylesheets(StyleManager.java:1179)
     at com.sun.javafx.application.PlatformImpl.lambda$_setPlatformUserAgentStylesheet$179(PlatformImpl.java:698)
     at com.sun.javafx.application.PlatformImpl$$Lambda$84/558920689.run(Unknown Source)
     at java.security.AccessController.doPrivileged(Native Method)
     at com.sun.javafx.application.PlatformImpl._setPlatformUserAgentStylesheet(PlatformImpl.java:697)
     at com.sun.javafx.application.PlatformImpl.setPlatformUserAgentStylesheet(PlatformImpl.java:548)
     at com.sun.javafx.application.PlatformImpl.setDefaultPlatformUserAgentStylesheet(PlatformImpl.java:512)
     at javafx.scene.control.Control.<clinit>(Control.java:87)
     ... 16 more
    java.lang.NullPointerException
     at base.webview.JFXPanelExt$2.run(JFXPanelExt.java:269)
     at com.sun.javafx.application.PlatformImpl.lambda$null$170(PlatformImpl.java:295)
     at com.sun.javafx.application.PlatformImpl$$Lambda$61/1601331386.run(Unknown Source)
     at java.security.AccessController.doPrivileged(Native Method)
     at com.sun.javafx.application.PlatformImpl.lambda$runLater$171(PlatformImpl.java:294)
     at com.sun.javafx.application.PlatformImpl$$Lambda$60/1534821193.run(Unknown Source)
     at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)


WORKAROUND:
We found a workaround to solve this problem:

try
{ // do this ...
	Thread thread = Thread.currentThread();
	if (thread.getContextClassLoader() == null)
	{
		thread.setContextClassLoader(JFXPanelExt.class.getClassLoader()); // a valid ClassLoader from somewhere else
	}
}
catch (SecurityException e)
{
	e.printStackTrace();
}
// ... before creating the WebView ...
WebView view = new WebView();
Comments
Closing this as no test case has been provided.
31-07-2015

Can you provide a simple test case that shows this? If so, we will reopen the bug and evaluate it. I suspect the JFXPanel initialization code or the PlatformImpl code that is called by JFXPanel, which would make this an App Model bug (similar to one I fixed for the standard Java launcher case).
27-03-2015

I did not use the JFX Stage. So no idea.
26-03-2015

@Frederic: please attach a test case so we can evaluate it. Question for you: does it only happen with JFXPanel or also with a JavaFX stage? The problem might be that the CCL is not being passed to the FX application thread correctly in the JFXPanel initialization case (in which case it might be an App Model bug).
18-03-2015

This seems a good candidate to backport to 8u60.
18-03-2015

Not clear if this is a WebView bug or a CSS bug (so adding Jonathan to the watch list).
18-03-2015