gmuecke / reflections

Automatically exported from code.google.com/p/reflections
Do What The F*ck You Want To Public License
0 stars 0 forks source link

can't reload class even though classloader support reloading it #131

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. using apache jci ReloadingClassLoader as class loader
                ReloadingClassLoader loader = new ReloadingClassLoader(ClassLoader.getSystemClassLoader());
        loader.addResourceStore(new FileResourceStore(new File("bin")));
        ReloadingListener listener = new ReloadingListener();

        listener.addReloadNotificationListener(loader);
        listener.addReloadNotificationListener(new ReloadNotificationListener() {

            public void handleNotification() {
                Application.this.changed = true;
            }
        });

        FilesystemAlterationMonitor fam = new FilesystemAlterationMonitor();
        fam.setInterval(1000);
        fam.addListener(new File("src/main/java"), listener);
        fam.start(); 
2. create new reflections when some files changed
                ConfigurationBuilder builder = ConfigurationBuilder.build(packages,
                loader);
        Reflections reflections = new Reflections(builder);

        for (Class<?> c : reflections.getSubTypesOf(BaseController.class)) {
            System.out.println(System.identityHashCode(c));
        }

3. expect load new class, but old class returned

below is a quick patch:
$ svn diff
Index: reflections/src/main/java/org/reflections/ReflectionUtils.java
===================================================================
--- reflections/src/main/java/org/reflections/ReflectionUtils.java  (revision 
165)
+++ reflections/src/main/java/org/reflections/ReflectionUtils.java  (working 
copy)
@@ -389,7 +389,7 @@
             }

             for (ClassLoader classLoader : ClasspathHelper.classLoaders(classLoaders)) {
-                try { return Class.forName(type, false, classLoader); }
+                try { return classLoader.loadClass(type); }
                 catch (Throwable e) { /*continue*/ }
             }

Original issue reported on code.google.com by zzzhc.st...@gmail.com on 13 Oct 2012 at 3:14

GoogleCodeExporter commented 8 years ago
fixed on trunk, comments are welcomed

Original comment by ronm...@gmail.com on 20 Feb 2013 at 9:04