XMLReaderFactory and classloader
Brought to you by:
dmegginson
I have run into a problem with your implementation of
XMLReaderFactory in the J2EE environment.
The problem is that your implementation uses
Class.forName. As I assume you certainly know, this is
not "up-to-date" (see
http://www.javageeks.com/Papers/ClassForName/ for details).
I therefore propose the attached patch.
Logged In: NO
(There seems to ba a bug when trying to submit an error
with an attachment - I got an error. Here is the patch.
- mnl@mnl.de)
*** XMLReaderFactory.java.orig Thu Nov 15 20:26:47 2001
--- XMLReaderFactory.java Sat Jan 12 14:47:54 2002
***************
*** 113,119 ****
throws SAXException
{
try {
! return
(XMLReader)(Class.forName(className).newInstance());
} catch (ClassNotFoundException e1) {
throw new SAXException("SAX2 driver class " +
className +
" not found", e1);
--- 113,120 ----
throws SAXException
{
try {
! ClassLoader cl =
Thread.currentThread().getContextClassLoader();
! return
(XMLReader)cl.loadClass(className).newInstance();
} catch (ClassNotFoundException e1) {
throw new SAXException("SAX2 driver class " +
className +
" not found", e1);
Logged In: NO
Patch got lost when I submitted the error:
*** XMLReaderFactory.java.orig Thu Nov 15 20:26:47 2001
--- XMLReaderFactory.java Sat Jan 12 14:47:54 2002
***************
*** 113,119 ****
throws SAXException
{
try {
! return
(XMLReader)(Class.forName(className).newInstance());
} catch (ClassNotFoundException e1) {
throw new SAXException("SAX2 driver class " +
className +
" not found", e1);
--- 113,120 ----
throws SAXException
{
try {
! ClassLoader cl =
Thread.currentThread().getContextClassLoader();
! return
(XMLReader)cl.loadClass(className).newInstance();
} catch (ClassNotFoundException e1) {
throw new SAXException("SAX2 driver class " +
className +
" not found", e1);
Logged In: YES
user_id=44117
This has been fixed in the sax2 r2pre2 and r2pre3
releases for many months now. And in a way that
doesn't impose an undesirable jdk 1.2 requirement.
UPGRADE!