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();
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();
- relates to
-
JDK-8165342 NPE when JavaFX loads default stylesheet or font families if CCL is null
- Resolved