Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Class.forName uses wrong classloader #380

Closed
GoogleCodeExporter opened this issue Mar 16, 2015 · 2 comments
Closed

Class.forName uses wrong classloader #380

GoogleCodeExporter opened this issue Mar 16, 2015 · 2 comments

Comments

@GoogleCodeExporter
Copy link

Class loading in Tomcat (and other web containers) is done by using a tree of 
classloaders[1]. Higher level classloaders cannot access lower level classes as 
they are invisible to them. The Tomcat distribution of Ontopia places 
ontopia.jar at the 'common' level (apache-tomcat/common/lib) for all webapps to 
use it. Individual webapps can contain additional classes at the 'webapp' level.

A typical usecase could be that a webapp defines classes to be used, e.g. as 
web-editor actions or logic:externalFunction. The current version of Ontopia 
cannot reach these implementations because it uses the wrong classloader in 
Class.forName invokes.

The default implementation of Class.forName uses 
this.getClass().getClassLoader() as classloader[2]. In the Ontopia Tomcat 
distribution, this will be the 'common' level classloader. If the call was made 
from a webapp, it cannot access classes at the 'webapp' level. The fix to this 
issue is to replace Class.forName(String) occurrences with 
Class.forName(String, boolean, ClassLoader) with the classloader used by the 
current thread as argument. This would preserve a possible lower level 
classloader from an individual webapp.

[1]: http://tomcat.apache.org/tomcat-5.5-doc/class-loader-howto.html
[2]: 
http://download.oracle.com/javase/6/docs/api/java/lang/Class.html#forName(java.l
ang.String,%20boolean,%20java.lang.ClassLoader)

Original issue reported on code.google.com by p.kruijsen on 19 Mar 2011 at 9:07

@GoogleCodeExporter
Copy link
Author

Fixed by revision r1763.

Original comment by p.kruijsen on 19 Mar 2011 at 9:18

  • Changed state: Fixed

@GoogleCodeExporter
Copy link
Author

Original comment by qsieb...@gmail.com on 27 Jan 2012 at 10:57

  • Added labels: Release5.2.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant