I cannot create a new WebView programatically. Simply calling new WebView()
causes the following exception:
java.lang.ExceptionInInitializerError
at javafx.web/javafx.scene.web.WebEngine.<clinit>(WebEngine.java:339)
at javafx.web/javafx.scene.web.WebView.<init>(WebView.java:260)
// omitting unrelated stacktraces
at javafx.base/com.sun.javafx.event.CompositeEventHandler$NormalEventFilterRecord.handleCapturingEvent(CompositeEventHandler.java:282)
at javafx.base/com.sun.javafx.event.CompositeEventHandler.dispatchCapturingEvent(CompositeEventHandler.java:98)
at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchCapturingEvent(EventHandlerManager.java:223)
at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchCapturingEvent(EventHandlerManager.java:180)
at javafx.base/com.sun.javafx.event.CompositeEventDispatcher.dispatchCapturingEvent(CompositeEventDispatcher.java:43)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:52)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at javafx.base/com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.base/javafx.event.Event.fireEvent(Event.java:198)
at javafx.graphics/javafx.scene.Scene$KeyHandler.process(Scene.java:4058)
at javafx.graphics/javafx.scene.Scene$KeyHandler.access$1500(Scene.java:4004)
at javafx.graphics/javafx.scene.Scene.processKeyEvent(Scene.java:2121)
at javafx.graphics/javafx.scene.Scene$ScenePeerListener.keyEvent(Scene.java:2595)
at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$KeyEventNotification.run(GlassViewEventHandler.java:217)
at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$KeyEventNotification.run(GlassViewEventHandler.java:149)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleKeyEvent$1(GlassViewEventHandler.java:248)
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:390)
at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.handleKeyEvent(GlassViewEventHandler.java:247)
at javafx.graphics/com.sun.glass.ui.View.handleKeyEvent(View.java:547)
at javafx.graphics/com.sun.glass.ui.View.notifyKey(View.java:971)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.UnsupportedOperationException: not implemented
at javafx.base/com.sun.javafx.logging.PlatformLogger.getName(PlatformLogger.java:121)
at javafx.web/com.sun.webkit.perf.PerfLogger.fullName(PerfLogger.java:155)
at javafx.web/com.sun.webkit.perf.PerfLogger.registerProbe(PerfLogger.java:201)
at javafx.web/com.sun.webkit.perf.PerfLogger.startCount(PerfLogger.java:227)
at javafx.web/com.sun.webkit.perf.PerfLogger.<init>(PerfLogger.java:90)
at javafx.web/com.sun.webkit.perf.PerfLogger.getLogger(PerfLogger.java:57)
at javafx.web/com.sun.webkit.perf.PerfLogger.getLogger(PerfLogger.java:84)
at javafx.web/com.sun.webkit.Invoker.<clinit>(Invoker.java:34)
... 37 more
Is it a bug? I am using OpenJFX 11.0.1 and OpenJDK 11.0.1.
Updates:
As mentioned in the comments this bug will be fixed in OpenJFX 12.
Here's the problem code from com.sun.javafx.logging.PlatformLogger
:
@Override
public String getName() {
throw new UnsupportedOperationException("not implemented");
}
As you can see, it does nothing but throw the observed exception. This is true of all the "implemented" java.lang.System.Logger
methods.
If you follow the code, as outlined by the stack trace you provide, the getName
method is invoked ultimately because a com.sun.webkit.perf.PerfLogger
is instantiated during the process of initializing the WebEngine
and, by extension, com.sun.webkit.Invoker
classes. However, getName
is only called when the PerfLogger
is enabled.
From a cursory glance, a PerfLogger
wraps a com.sun.javafx.logging.PlatformLogger
which itself wraps a System.Logger
. The PerfLogger
is enabled if the System.Logger
returns true for isLoggable(System.Logger.Level.FINE)
at the time the PerfLogger
is constructed.
In this case, this process results in a System.Logger
with the name "com.sun.webkit.perf.Locks"
being created. What this means is that you can avoid the UnsupportedOperationException
if you configure this System.Logger
to not log anything at Level.FINE
or "lower". Doing this will make the PerfLogger
"disabled" which prevents getName
from being called down the line.
Note: This is based on the source code of OpenJFX 11.0.1. Everything mentioned is an implementation detail and can change without notice.