diff -r e1eced12249a javafx-ui-common/src/com/sun/javafx/Utils.java --- a/javafx-ui-common/src/com/sun/javafx/Utils.java Wed May 30 17:35:57 2012 -0700 +++ b/javafx-ui-common/src/com/sun/javafx/Utils.java Fri Jun 01 09:55:32 2012 -0700 @@ -1009,7 +1009,60 @@ return PlatformUtil.isUnix(); } - /*************************************************************************** + /** + * Utility for loading a class in a manner that will work with multiple + * class loaders, as is typically found in OSGI modular applications. + * In particular, this method will attempt to just load the class + * identified by className. If that fails, it attempts to load the + * class using the current thread's context class loader. If that fails, + * it attempts to use the class loader of the supplied "instance", and + * if it still fails it walks up the class hierarchy of the instance + * and attempts to use the class loader of each class in the super-type + * hierarchy. + * + * @param className The name of the class we want to load + * @param instance An optional instance used to help find the class to load + * @return The class. Cannot return null + * @throws ClassNotFoundException If the class cannot be found using any technique. + */ + public static Class loadClass(final String className, final Object instance) + throws ClassNotFoundException + { + try { + // Try just loading the class + return Class.forName(className); + } catch (ClassNotFoundException ex) { + // RT-17525 : Use context class loader only if Class.forName fails. + if (Thread.currentThread().getContextClassLoader() != null) { + try { + return Thread.currentThread().getContextClassLoader().loadClass(className); + } catch (ClassNotFoundException ex2) { + // Do nothing, just fall through + } + } + + // RT-14177: Try looking up the class using the class loader of the + // current class, walking up the list of superclasses + // and checking each of them, before bailing and using + // the context class loader. + if (instance != null) { + Class currentType = instance.getClass(); + while (currentType != null) { + try { + return currentType.getClassLoader().loadClass(className); + } catch (ClassNotFoundException ex2) { + currentType = currentType.getSuperclass(); + } + } + } + + // We failed to find the class using any of the above means, so we're going + // to just throw the ClassNotFoundException that we caught earlier + throw ex; + } + } + + /*************************************************************************** * * * Unicode-related utilities * * * diff -r e1eced12249a javafx-ui-controls/src/javafx/scene/control/Control.java --- a/javafx-ui-controls/src/javafx/scene/control/Control.java Wed May 30 17:35:57 2012 -0700 +++ b/javafx-ui-controls/src/javafx/scene/control/Control.java Fri Jun 01 09:55:32 2012 -0700 @@ -25,6 +25,7 @@ package javafx.scene.control; +import com.sun.javafx.Utils; import com.sun.javafx.css.*; import com.sun.javafx.css.converters.StringConverter; import java.lang.reflect.Constructor; @@ -49,7 +50,6 @@ import com.sun.javafx.logging.PlatformLogger; import com.sun.javafx.scene.control.Logging; -import javafx.collections.ObservableList; /** * Base class for all user interface controls. A "Control" is a node in the @@ -964,20 +964,9 @@ Logging.getControlsLogger().severe(msg); return; } - + try { - Class skinClass; - // RT-17525 : Use context class loader only if Class.forName fails. - try { - skinClass = Class.forName(skinClassName.get()); - } catch (ClassNotFoundException clne) { - if (Thread.currentThread().getContextClassLoader() != null) { - skinClass = Thread.currentThread().getContextClassLoader().loadClass(skinClassName.get()); - } else { - throw clne; - } - } - + final Class skinClass = Utils.loadClass(skinClassName.get(), this); Constructor[] constructors = skinClass.getConstructors(); Constructor skinConstructor = null; for (Constructor c : constructors) { @@ -1038,8 +1027,6 @@ } - - /*************************************************************************** * * * StyleSheet Handling * diff -r e1eced12249a javafx-ui-controls/src/javafx/scene/control/PopupControl.java --- a/javafx-ui-controls/src/javafx/scene/control/PopupControl.java Wed May 30 17:35:57 2012 -0700 +++ b/javafx-ui-controls/src/javafx/scene/control/PopupControl.java Fri Jun 01 09:55:32 2012 -0700 @@ -24,6 +24,7 @@ */ package javafx.scene.control; +import com.sun.javafx.Utils; import javafx.beans.property.DoubleProperty; import javafx.beans.property.DoublePropertyBase; import javafx.beans.property.ObjectProperty; @@ -1153,8 +1154,6 @@ } private void loadSkinClass() { - - if (skinClassName == null || skinClassName.get() == null || skinClassName.get().isEmpty()) { @@ -1170,17 +1169,7 @@ } try { - Class skinClass; - // RT-17525 : Use context class loader only if Class.forName fails. - try { - skinClass = Class.forName(skinClassName.get()); - } catch (ClassNotFoundException clne) { - if (Thread.currentThread().getContextClassLoader() != null) { - skinClass = Thread.currentThread().getContextClassLoader().loadClass(skinClassName.get()); - } else { - throw clne; - } - } + final Class skinClass = Utils.loadClass(skinClassName.get(), this); Constructor[] constructors = skinClass.getConstructors(); Constructor skinConstructor = null; for (Constructor c : constructors) {