@Test(expected = ClassNotFoundException.class) @SuppressWarnings("unchecked") public void testLoadClassNoClass() throws Exception { Bundle bundle = mock(Bundle.class); when(bundle.loadClass("NotFoundClass")).thenThrow(ClassNotFoundException.class); BundleDelegatingClassLoader classLoader = new BundleDelegatingClassLoader(bundle, getClass().getClassLoader()); classLoader.loadClass("NotFoundClass", false); }
protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException { Class<?> clazz; try { clazz = findClass(name); } catch (ClassNotFoundException cnfe) { if (classLoader != null) { try { clazz = classLoader.loadClass(name); } catch (ClassNotFoundException e) { throw new ClassNotFoundException(String.format("[%s] from bundle [%s] (%s)", name, bundle.getBundleId(), bundle.getSymbolicName())); } } else { throw new ClassNotFoundException(String.format("[%s] from bundle [%s] (%s)", name, bundle.getBundleId(), bundle.getSymbolicName())); } } if (resolve) { resolveClass(clazz); } return clazz; }
BundleDelegatingClassLoader extends ClassLoader { protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException { Class<?> clazz; try { clazz = findClass(name); } catch (ClassNotFoundException cnfe) { if (classLoader != null) { try { clazz = classLoader.loadClass(name); } catch (ClassNotFoundException e) { throw new ClassNotFoundException(String.format("[%s] from bundle [%s] (%s)", name, bundle.getBundleId(), bundle.getSymbolicName())); } } else { throw new ClassNotFoundException(String.format("[%s] from bundle [%s] (%s)", name, bundle.getBundleId(), bundle.getSymbolicName())); } } if (resolve) { resolveClass(clazz); } return clazz; } }
BundleDelegatingClassLoader extends ClassLoader { protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException { Class<?> clazz; try { clazz = findClass(name); } catch (ClassNotFoundException cnfe) { if (classLoader != null) { try { clazz = classLoader.loadClass(name); } catch (ClassNotFoundException e) { throw new ClassNotFoundException(String.format("[%s] from bundle [%s] (%s)", name, bundle.getBundleId(), bundle.getSymbolicName())); } } else { throw new ClassNotFoundException(String.format("[%s] from bundle [%s] (%s)", name, bundle.getBundleId(), bundle.getSymbolicName())); } } if (resolve) { resolveClass(clazz); } return clazz; } BundleDelegatingClassLoader(Bundle bundle);  BundleDelegatingClassLoader(Bundle bundle, ClassLoader classLoader); }
BundleDelegatingClassLoader extends ClassLoader { protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException { Class<?> clazz; try { clazz = findClass(name); } catch (ClassNotFoundException cnfe) { if (classLoader != null) { try { clazz = classLoader.loadClass(name); } catch (ClassNotFoundException e) { throw new ClassNotFoundException(String.format("[%s] from bundle [%s] (%s)", name, bundle.getBundleId(), bundle.getSymbolicName())); } } else { throw new ClassNotFoundException(String.format("[%s] from bundle [%s] (%s)", name, bundle.getBundleId(), bundle.getSymbolicName())); } } if (resolve) { resolveClass(clazz); } return clazz; } BundleDelegatingClassLoader(Bundle bundle);  BundleDelegatingClassLoader(Bundle bundle, ClassLoader classLoader); Bundle getBundle(); @Override String toString(); }
BundleDelegatingClassLoader extends ClassLoader { protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException { Class<?> clazz; try { clazz = findClass(name); } catch (ClassNotFoundException cnfe) { if (classLoader != null) { try { clazz = classLoader.loadClass(name); } catch (ClassNotFoundException e) { throw new ClassNotFoundException(String.format("[%s] from bundle [%s] (%s)", name, bundle.getBundleId(), bundle.getSymbolicName())); } } else { throw new ClassNotFoundException(String.format("[%s] from bundle [%s] (%s)", name, bundle.getBundleId(), bundle.getSymbolicName())); } } if (resolve) { resolveClass(clazz); } return clazz; } BundleDelegatingClassLoader(Bundle bundle);  BundleDelegatingClassLoader(Bundle bundle, ClassLoader classLoader); Bundle getBundle(); @Override String toString();  }