Patch for 1.1.1 NPE under Apache service wrapper on Windows

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Patch for 1.1.1 NPE under Apache service wrapper on Windows

Rob Heittman
This particular environment has funny classloader behavior.  So only
the System classloader resolves.

Accordingly, Engine NPEs due to a bad assumption here:

            ClassLoader cl = getClassLoader();  // this may return
null since it doesn't try System classloader
            URL configURL = cl.getResource(providerResource); // boom

My patch was to fix getClassLoader(), but while an effective fix, I'm
not sure that's what should be done:

Index: modules/org.restlet/src/org/restlet/util/Engine.java
===================================================================
--- modules/org.restlet/src/org/restlet/util/Engine.java (revision 3945)
+++ modules/org.restlet/src/org/restlet/util/Engine.java (working copy)
@@ -107,6 +107,10 @@
             result = Class.class.getClassLoader();
         }

+        if (result == null) {
+            result = ClassLoader.getSystemClassLoader();
+        }
+
         return result;
     }
Reply | Threaded
Open this post in threaded view
|

RE: Patch for 1.1.1 NPE under Apache service wrapper on Windows

jlouvel
Administrator

Hi Rob,

Thanks for the patch. I applied to SVN trunk and branch 1.1.

In some cases, only doing a Class.forName() will work because it will use
the caller object's classloader (internal code to JRE). That's why we also
have an Engine#loadClass() method for loading classes.

Best regards,
Jérôme Louvel
--
Restlet ~ Founder and Lead developer ~ http://www.restlet.org
Noelios Technologies ~ Co-founder ~ http://www.noelios.com 

-----Message d'origine-----
De : Rob Heittman [mailto:[hidden email]]
Envoyé : jeudi 6 novembre 2008 23:28
À : [hidden email]
Objet : Patch for 1.1.1 NPE under Apache service wrapper on Windows

This particular environment has funny classloader behavior.  So only
the System classloader resolves.

Accordingly, Engine NPEs due to a bad assumption here:

            ClassLoader cl = getClassLoader();  // this may return
null since it doesn't try System classloader
            URL configURL = cl.getResource(providerResource); // boom

My patch was to fix getClassLoader(), but while an effective fix, I'm
not sure that's what should be done:

Index: modules/org.restlet/src/org/restlet/util/Engine.java
===================================================================
--- modules/org.restlet/src/org/restlet/util/Engine.java (revision
3945)
+++ modules/org.restlet/src/org/restlet/util/Engine.java (working
copy)
@@ -107,6 +107,10 @@
             result = Class.class.getClassLoader();
         }

+        if (result == null) {
+            result = ClassLoader.getSystemClassLoader();
+        }
+
         return result;
     }