/** * Make a different ClassLoader that loads the same URLs as this one, and use it to compile * an {@code @RetroWeibo} class. If Velocity loads its managers using the context class loader, * and that loader is still the original one that loaded this test, then it will find the * original copy of the Velocity classes rather than the one from the new loader, and fail. * * <p>This test assumes that the test class was loaded by a URLClassLoader and that that loader's * URLs also include the Velocity classes. */ public void testClassLoaderHack() throws Exception { URLClassLoader myLoader = (URLClassLoader) getClass().getClassLoader(); URLClassLoader newLoader = new URLClassLoader(myLoader.getURLs(), myLoader.getParent()); String velocityClassName = Velocity.class.getName(); Class<?> myVelocity = myLoader.loadClass(velocityClassName); Class<?> newVelocity = newLoader.loadClass(velocityClassName); assertThat(myVelocity).isNotEqualTo(newVelocity); Runnable test = (Runnable) newLoader.loadClass(RunInClassLoader.class.getName()).newInstance(); assertThat(test.getClass()).isNotEqualTo(RunInClassLoader.class); test.run(); }
/** * Make a different ClassLoader that loads the same URLs as this one, and use it to compile * an {@code @RetroFacebook} class. If Velocity loads its managers using the context class loader, * and that loader is still the original one that loaded this test, then it will find the * original copy of the Velocity classes rather than the one from the new loader, and fail. * * <p>This test assumes that the test class was loaded by a URLClassLoader and that that loader's * URLs also include the Velocity classes. */ public void testClassLoaderHack() throws Exception { URLClassLoader myLoader = (URLClassLoader) getClass().getClassLoader(); URLClassLoader newLoader = new URLClassLoader(myLoader.getURLs(), myLoader.getParent()); String velocityClassName = Velocity.class.getName(); Class<?> myVelocity = myLoader.loadClass(velocityClassName); Class<?> newVelocity = newLoader.loadClass(velocityClassName); assertThat(myVelocity).isNotEqualTo(newVelocity); Runnable test = (Runnable) newLoader.loadClass(RunInClassLoader.class.getName()).newInstance(); assertThat(test.getClass()).isNotEqualTo(RunInClassLoader.class); test.run(); }
/** * Make a different ClassLoader that loads the same URLs as this one, and use it to compile * an {@code @RetroFacebook} class. If Velocity loads its managers using the context class loader, * and that loader is still the original one that loaded this test, then it will find the * original copy of the Velocity classes rather than the one from the new loader, and fail. * * <p>This test assumes that the test class was loaded by a URLClassLoader and that that loader's * URLs also include the Velocity classes. */ public void testClassLoaderHack() throws Exception { URLClassLoader myLoader = (URLClassLoader) getClass().getClassLoader(); URLClassLoader newLoader = new URLClassLoader(myLoader.getURLs(), myLoader.getParent()); String velocityClassName = Velocity.class.getName(); Class<?> myVelocity = myLoader.loadClass(velocityClassName); Class<?> newVelocity = newLoader.loadClass(velocityClassName); assertThat(myVelocity).isNotEqualTo(newVelocity); Runnable test = (Runnable) newLoader.loadClass(RunInClassLoader.class.getName()).newInstance(); assertThat(test.getClass()).isNotEqualTo(RunInClassLoader.class); test.run(); }
/** * Make a different ClassLoader that loads the same URLs as this one, and use it to compile * an {@code @AutoJson} class. If Velocity loads its managers using the context class loader, * and that loader is still the original one that loaded this test, then it will find the * original copy of the Velocity classes rather than the one from the new loader, and fail. * * <p>This test assumes that the test class was loaded by a URLClassLoader and that that loader's * URLs also include the Velocity classes. */ public void testClassLoaderHack() throws Exception { URLClassLoader myLoader = (URLClassLoader) getClass().getClassLoader(); URLClassLoader newLoader = new URLClassLoader(myLoader.getURLs(), myLoader.getParent()); String velocityClassName = Velocity.class.getName(); Class<?> myVelocity = myLoader.loadClass(velocityClassName); Class<?> newVelocity = newLoader.loadClass(velocityClassName); assertThat(myVelocity).isNotEqualTo(newVelocity); Runnable test = (Runnable) newLoader.loadClass(RunInClassLoader.class.getName()).newInstance(); assertThat(test.getClass()).isNotEqualTo(RunInClassLoader.class); test.run(); }