You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by bu...@apache.org on 2009/12/20 02:05:32 UTC
DO NOT REPLY [Bug 48414] New: Use of Class.forName may not work well
in osgi environment
https://issues.apache.org/bugzilla/show_bug.cgi?id=48414
Summary: Use of Class.forName may not work well in osgi
environment
Product: Tomcat 7
Version: trunk
Platform: PC
OS/Version: Mac OS X 10.4
Status: NEW
Severity: normal
Priority: P2
Component: Catalina
AssignedTo: dev@tomcat.apache.org
ReportedBy: djencks@apache.org
Created an attachment (id=24737)
--> (https://issues.apache.org/bugzilla/attachment.cgi?id=24737)
Simple use of InstanceManager to create listener objects.
In the geronimo-tomcat7/osgi integration we're experiencing a problem with the
use of Class.forName to load listener classes in
StandardContext.createWrapper(). Geronimo has some listener classes that are
not in the tomcat bundle and aren't available to Class.forName. Using the
instanceManager seems to work fine.
If you don't like allowing application classes to be loaded for these listeners
or don't expect the instance manager to be able to load tomcat classes then
perhaps adding another method to instanceManager to create system objects would
be a good solution. The attached patch just uses the existing InstanceManager
methods.
--
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
DO NOT REPLY [Bug 48414] Use of Class.forName may not work well in
osgi environment
Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=48414
Mark Thomas <ma...@apache.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |WONTFIX
--- Comment #7 from Mark Thomas <ma...@apache.org> 2010-02-02 09:22:36 GMT ---
The consensus among the Tomcat developers was that a classloader was the place
to implement this. Therefore resolving as WONTFIX.
--
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
DO NOT REPLY [Bug 48414] Use of Class.forName may not work well in
osgi environment
Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=48414
--- Comment #5 from david jencks <dj...@apache.org> 2010-01-05 11:24:12 UTC ---
Created an attachment (id=24799)
--> (https://issues.apache.org/bugzilla/attachment.cgi?id=24799)
2nd half of patch to use newSystemInstance for system objects
2nd half of patch
--
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
DO NOT REPLY [Bug 48414] Use of Class.forName may not work well in
osgi environment
Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=48414
--- Comment #3 from david jencks <dj...@apache.org> 2009-12-20 02:28:54 UTC ---
Looking at the javadoc for Class.forName(String className) gives
Returns the Class object associated with the class or interface with the given
string name. Invoking this method is equivalent to:
Class.forName(className, true, currentLoader)
where currentLoader denotes the defining class loader of the current class.
Lets suppose we have catalina jar containing StandardContext, InstanceListener,
ContainerListener, and NamingContextListener, and an integration jar containing
GeronimoStandardContext extends StandardContext and
DispatchListener implements InstanceListener
Furthermore lets suppose these are separate bundles in an osgi environment
(i.e. the integration bundle is not a fragment bundle extending catalina.jar,
but a separate bundle)
I did a little experimentation in the debugger.
It turns out that:
1. Class.forName(String className)
here means
Class.forName(className, true, StandardContext.class.getClassLoader())
and not
Class.forName(className, true, GeronimoStandardContext.class.getClassLoader())
even though the current object is an instance of GeronimoStandardContext.
So, there is no chance of loading any classes from the integration bundle.
Replacing the code with Class.forName(className, true,
StandardContext.class.getClassLoader()) won't work.
2. replacing the code with
Class.forName(className, true, GeronimoStandardContext.class.getName()) doesn't
work either, since in osgi this classloader can only load classes from the jar
GeronimoStandardContext is in, not catalina.jar.
If bundle is the Bundle for the integration jar,
bundle.loadClass(className) does work for all listeners, whether from catalina
or the integration.
So, AFAICT the choices are:
1. Require any listeners in an osgi environment to be in fragment bundles
associated with catalina.jar
2. Allow some other way to load classes in an osgi environment, such as from an
appropriate bundle.
Since I'm not really interested in telling tomcat how to load classes for
itself, I suggested using the existing integration point of InstanceManager
which allows integrations to specify how to load classes for themselves. I
realize that the instance manager method in my patch allows access to
application classes, and I'm not 100% sure of how tomcat distinguishes between
system and application classes, so if it's a bad idea to allow applications to
contain these listener classes, I suggested adding a newSystemInstance(String
className) to the InstanceManager interface. However I really hope you'll
agree that only allowing extension listeners in fragment bundles is
unnecessarily limiting.
--
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
DO NOT REPLY [Bug 48414] Use of Class.forName may not work well in
osgi environment
Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=48414
--- Comment #2 from Mark Thomas <ma...@apache.org> 2009-12-19 19:40:39 GMT ---
Using the InstanceManager in this way feels more like a convenience since
Germonimo's custom InstanceManager happens to have visibility across multiple
bundles rather than the 'right' way to do things.
I don't know the Geronimo code at all so can't say what the right solution
would be but my impression based on this issue description is either the class
loader hierarchy or the bundle contents needs tweaking.
I'm leaning towards WONTFIX for this issue at the moment.
--
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
DO NOT REPLY [Bug 48414] Use of Class.forName may not work well in
osgi environment
Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=48414
--- Comment #1 from david jencks <dj...@apache.org> 2009-12-19 17:06:29 UTC ---
This is also discussed in https://issues.apache.org/jira/browse/GERONIMO-4992
--
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
DO NOT REPLY [Bug 48414] Use of Class.forName may not work well in
osgi environment
Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=48414
david jencks <dj...@apache.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Attachment #24737|0 |1
is obsolete| |
--- Comment #4 from david jencks <dj...@apache.org> 2010-01-05 11:23:12 UTC ---
Created an attachment (id=24798)
--> (https://issues.apache.org/bugzilla/attachment.cgi?id=24798)
half of patch to use new newSystemInstance InstanceManager method
add method to instance manager so system and app objects can be distinguished.
In two patches.
--
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
DO NOT REPLY [Bug 48414] Use of Class.forName may not work well in
osgi environment
Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=48414
--- Comment #6 from david jencks <dj...@apache.org> 2010-01-16 00:28:28 UTC ---
IIRC there were two objections to the patch on the dev list:
1. it doesn't cover all uses of Class.forName()
2. it uses the per-web-app InstanceManager to create the system listeners for a
web app rather than a system-wide object
and it was suggested that injecting a system-wide classloader for reflective
class loading would be a good solution.
I'm willing to work on solving (1) and (2) through something like a system-wide
instance manager, but not through direct use of a classloader. If the
developers insist on a classloader I'd suggest closing this as "wont' fix"
--
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org