Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8107304

ClassCastException on Nodes Loaded via a Different Classloader

    Details

      Description

      I ran into some issues with running JavaFX with multiple Classloaders for restricting security of loaded classes. While the reflection API supports working with different classloaders, adding in a Node that was loaded by a sub-classloader resulted in a ClassCastException.

      The scenario was to create a set of nested classloaders like this:
      Main classloader (contains JavaFX files and Main application)
          - URLClassloader (contains custom nodes for the application)

      When nodes from the nested URLClassloader are added to the scene, they will cause the whole application to stop functioning with a Security Exception in the CSS/stylesheet support (even when no stylesheet was specified).

      This bug makes it impossible to do the following:

          * Securely load portions of a user interface (required for WidgetFX security)
          * Restrict portions of a JavaFX application to the sandbox (required for WidgetFX security)
          * Share the JavaFX runtime between Applets (which will eventually be the case once JavaFX is pushed into the JRE or a JRE module)

      Here is a stack trace from my application:
      com.sun.stylesheet.StylesheetException: java.lang.reflect.InvocationTargetException
      at com.sun.stylesheet.types.TypeManager.getStyleable(Unknown Source)
      at com.sun.stylesheet.javafx.FXObjectStyleSupport.getStyleableChildren(Unknown Source)
      at com.sun.stylesheet.styleable.DefaultStyleable.getStyleableChildren(Unknown Source)
      at com.sun.stylesheet.Stylesheet.applyTo(Unknown Source)
      at com.sun.stylesheet.Stylesheet.applyTo(Unknown Source)
      at com.sun.stylesheet.Stylesheet.applyTo(Unknown Source)
      at com.sun.stylesheet.Stylesheet.applyTo(Unknown Source)
      at com.sun.stylesheet.Stylesheet.applyTo(Unknown Source)
      at com.sun.stylesheet.Stylesheet.applyTo(Unknown Source)
      at com.sun.stylesheet.Stylesheet.applyTo(Unknown Source)
      at com.sun.stylesheet.Stylesheet.applyTo(Unknown Source)
      at com.sun.stylesheet.Stylesheet.applyTo(Unknown Source)
      at com.sun.stylesheet.Stylesheet.applyTo(Unknown Source)
      at com.sun.stylesheet.Stylesheet.applyTo(Unknown Source)
      at com.sun.stylesheet.Stylesheet.applyTo(Unknown Source)
      at javafx.scene.Scene.userInit$(Unknown Source)
      at javafx.scene.Scene.initialize$(Unknown Source)
      at org.widgetfx.ui.DockDialog.loadContent$impl(DockDialog.fx:345)
      at org.widgetfx.ui.DockDialog.loadContent(DockDialog.fx:69)
      at org.widgetfx.ui.DockDialog.postInit$(DockDialog.fx:181)
      at org.widgetfx.ui.DockDialog.initialize$(DockDialog.fx:69)
      at org.widgetfx.ui.DockDialog.createInstance(DockDialog.fx:59)
      at org.widgetfx.Main.javafx$run$(Main.fx:45)
      Caused by: java.lang.reflect.InvocationTargetException
      at sun.reflect.GeneratedConstructorAccessor24.newInstance(Unknown Source)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
      at java.lang.reflect.Constructor.newInstance(Unknown Source)
      at com.sun.stylesheet.types.TypeManager.getStyleable(Unknown Source)
      at com.sun.stylesheet.javafx.FXObjectStyleSupport.getStyleableChildren(Unknown Source)
      at com.sun.stylesheet.styleable.DefaultStyleable.getStyleableChildren(Unknown Source)
      at com.sun.stylesheet.Stylesheet.applyTo(Unknown Source)
      at com.sun.stylesheet.Stylesheet.applyTo(Unknown Source)
      at com.sun.stylesheet.Stylesheet.applyTo(Unknown Source)
      at com.sun.stylesheet.Stylesheet.applyTo(Unknown Source)
      at com.sun.stylesheet.Stylesheet.applyTo(Unknown Source)
      at com.sun.stylesheet.Stylesheet.applyTo(Unknown Source)
      at com.sun.stylesheet.Stylesheet.applyTo(Unknown Source)
      at com.sun.stylesheet.Stylesheet.applyTo(Unknown Source)
      at com.sun.stylesheet.Stylesheet.applyTo(Unknown Source)
      at com.sun.stylesheet.Stylesheet.applyTo(Unknown Source)
      at com.sun.stylesheet.Stylesheet.applyTo(Unknown Source)
      at com.sun.stylesheet.Stylesheet.applyTo(Unknown Source)
      at javafx.scene.Scene.userInit$(Unknown Source)
      at javafx.scene.Scene.initialize$(Unknown Source)
      at org.widgetfx.ui.DockDialog.loadContent$impl(DockDialog.fx:345)
      at org.widgetfx.ui.DockDialog.loadContent(DockDialog.fx:69)
      at org.widgetfx.ui.DockDialog.postInit$(DockDialog.fx:181)
      at org.widgetfx.ui.DockDialog.initialize$(DockDialog.fx:69)
      at org.widgetfx.ui.DockDialog.createInstance(DockDialog.fx:59)
      at org.widgetfx.Main.javafx$run$(Main.fx:45)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      at java.lang.reflect.Method.invoke(Unknown Source)
      at com.sun.javafx.runtime.provider.AWT_EDT_RuntimeProvider$1.run(Unknown Source)
      at java.awt.event.InvocationEvent.dispatch(Unknown Source)
      at java.awt.EventQueue.dispatchEvent(Unknown Source)
      at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
      at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
      at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
      at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
      at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
      at java.awt.EventDispatchThread.run(Unknown Source)
      Caused by: com.sun.stylesheet.StylesheetException: java.lang.reflect.InvocationTargetException
      at com.sun.stylesheet.types.TypeManager.getStyleSupport(Unknown Source)
      at com.sun.stylesheet.styleable.DefaultStyleable.getStyleSupport(Unknown Source)
      at com.sun.stylesheet.styleable.DefaultStyleable.<init>(Unknown Source)
      ... 39 more
      Caused by: java.lang.reflect.InvocationTargetException
      at sun.reflect.GeneratedConstructorAccessor26.newInstance(Unknown Source)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
      at java.lang.reflect.Constructor.newInstance(Unknown Source)
      ... 42 more
      Caused by: java.lang.RuntimeException: java.lang.ClassNotFoundException: org.widgetfx.widget.clock.Clock
      at javafx.reflect.FXLocal$Context.findClass(Unknown Source)
      at javafx.reflect.FXLocal$Context.findClass(Unknown Source)
      at com.sun.stylesheet.javafx.FXObjectStyleSupport.<init>(Unknown Source)
      ... 45 more
      Caused by: java.lang.ClassNotFoundException: org.widgetfx.widget.clock.Clock
      at java.net.URLClassLoader$1.run(Unknown Source)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(Unknown Source)
      at com.sun.jnlp.JNLPClassLoader.findClass(JNLPClassLoader.java:257)
      at java.lang.ClassLoader.loadClass(Unknown Source)
      at java.lang.ClassLoader.loadClass(Unknown Source)
      at java.lang.ClassLoader.loadClassInternal(Unknown Source)
      at java.lang.Class.forName0(Native Method)
      at java.lang.Class.forName(Unknown Source)
      ... 48 more

        Attachments

          Activity

            People

            • Assignee:
              dgrieve David Grieve
              Reporter:
              schin Stephen Chin (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported: