You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by bu...@apache.org on 2003/10/30 10:39:58 UTC

DO NOT REPLY [Bug 24244] New: - Use of ContextClassLoader is not appropriate

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=24244>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=24244

Use of ContextClassLoader is not appropriate

           Summary: Use of ContextClassLoader is not appropriate
           Product: Xerces2-J
           Version: 2.5.0
          Platform: Other
        OS/Version: Other
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: JAXP
        AssignedTo: xerces-j-dev@xml.apache.org
        ReportedBy: extern.thomas.pasch@volkswagen.de


On jdk >=1.2 (but <1.4) xerces uses the ContextClassLoader to load classes of 
its own distribution. This is never appropriate and will lead to 
ClassCastException in a J2EE setting.

For loading classes of its own distribution, the (current) ClassLoader that has 
loaded the distribution classes (i.e. xercesImpl.jar) should be used.

Glory Details:
--------------
The problem shows up when there is a (outdated) xerces in your (ClassLoader) 
path but you want to use a newer version of xerces in your application. Note 
that this is NOT an obscure setting but the normal case in every J2EE (1.3) 
application because you are guarantied to have JAXP XML access, but often to an 
outdated product (in my case I'm using IBM WAS 5.0.1 on Solaris).  

One of the possible solution is to load the JAXP factory classes by a self 
created (URL)ClassLoader. (Note that this is not 100% to the specs but works on 
most application servers I know.)

The problem however arises from within xerces. It exist in some variants but 
basically boils down to the following:

1. 
While creating a SAX/DOM object xerces creates a XMLParserConfiguration first. 
For example, when trying to instantiate a 
org.apache.xerces.jaxp.DocumentBuilderImpl (by means of 
org.apache.xerces.jaxp.DocumentBuilderFactoryImpl) first a 
XMLParserConfiguration is created by org.apache.xerces.util.ObjectFactory 
invoked by org.apache.xerces.parsers.DOMParser(SymbolTable, XMLGrammarPool).

2.
ObjectFactory.findClassLoader(), however, uses the ContextClassLoader to load 
the Class "org.apache.xerces.xni.parser.XMLParserConfiguration". BUMMER! This 
is the (outdated) class of the old version of xerces.

3.
Xerces 2.5.0 fails miserably because of a ClassCastException. Typical 
stacktrace is:
java.lang.IllegalArgumentException: 
org.apache.xerces.parsers.StandardParserConfiguration
        at org.apache.xerces.jaxp.DocumentBuilderFactoryImpl.setAttribute
(DocumentBuilderFactoryImpl.java:128)

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org