You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Alan Ezust <al...@gmail.com> on 2005/10/18 01:52:39 UTC

Re: Question about SAX & Xerces

Elliotte Rusty Harold wrote:

>Tech Rams wrote:
>> JDK 1.5 has xerces built-in, though under a different
>> package name (com.sun.org.apache.xerces.internal).
>>
>> Look at
>> >http://java.sun.com/j2se/1.5.0/docs/api/javax/xml/parsers/SAXParserFactory.html#newInstance()
>> to know how factory implementation is found. The
>> default implementation is the one that comes with JDK
>> 1.5, that is xerces.
>>

>Please don't. SAXParserFactory is a disaster waiting to happen, If you
>use it, you'll only find yourself back here in a week pleading for help
>with undiagnosable bugs. It was designed for SAX1. In 2005 nobody should
>be using SAX1, SAXParser, or SAXParserFactory. Use XMLReader and
>XMLReaderFactory instead.

If SAXParserFactory is to be avoided, then why is it used by the JDK 1.5 API?
In particular, I am wondering about this

java.beans.XMLDecoder.readObject(XMLDecoder.java:201)

Which is currently throwing a ClassCastException due to this code:


  public Object readObject() {
	if (in == null) {
	    return null;
	}
        if (handler == null) {
            SAXParserFactory factory = SAXParserFactory.newInstance();

The classCastException is thrown here:

   public static SAXParserFactory newInstance() {
        try {
            return (SAXParserFactory) FactoryFinder.find(
                /* The default property name according to the JAXP spec */
                "javax.xml.parsers.SAXParserFactory",
                /* The fallback implementation class name */
                "com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl");
        } catch (FactoryFinder.ConfigurationError e) {
            throw new FactoryConfigurationError(e.getException(),
                                                e.getMessage());
        }
    }


Why isn't the ClassCastException handled here, or in JAXP?
Is JAXP.readObject also deprecated? What should I use instead?
Is this a known issue with JAXP?

PS: I have Xerces 2.7.1 installed in $JAVA_HOME/lib/endorsed
and I am using JDK 1.5_05

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


Re: Question about SAX & Xerces

Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Alan Ezust <al...@gmail.com> wrote on 10/18/2005 01:08:03 AM:

> On 10/17/05, Elliotte Harold <el...@metalab.unc.edu> wrote:
> > Alan Ezust wrote:
> >
> > > If SAXParserFactory is to be avoided, then why is it used by the
> JDK 1.5 API?
> > > In particular, I am wondering about this
> >
> > The programmers at Sun make the same mistakes everyone else does.
> > Remember, they invented SAXParserFactory in the first place.
> 
> Gads, I just realized that the sourcecode for parts of JAXP aren't
> even included in the JDK 1.5 src.zip - how annoying. I was trying to
> re-engineer the offending classes to use the new SAX API, but I can't
> find the sourcecode for
> com.sun.beans.ObjectHandler! I wonder why it's so separate from the
> rest of the src.zip.
>
> > Why it's throwing a ClassCastException, I don't know. Sounds like a 
bug.
> > Try printing a stack trace. However,
> 
> java.lang.ClassCastException:
> org.apache.xerces.jaxp.SAXParserFactoryImpl
>  at 
javax.xml.parsers.SAXParserFactory.newInstance(SAXParserFactory.java:107)
>  at java.beans.XMLDecoder.readObject(XMLDecoder.java:201)
>  at 
org.homedns.krolain.util.InstallInfo.loadInstallPath(InstallInfo.java:60)
>  at org.homedns.krolain.MochaJournal.JLJSettings.
> LoadSettings(JLJSettings.java:172)
>  at livejournal.LoginPane._load(LoginPane.java:117)
>  at livejournal.LoginPane.initComponents(LoginPane.java:112)
>  at livejournal.LoginPane.<init>(LoginPane.java:50)
>  at livejournal.LiveJournalPanel.<init>(LiveJournalPanel.java:25)
>  at sun.reflect.NativeConstructorAccessorImpl.newInstance0 (Native 
Method)
>  at sun.reflect.NativeConstructorAccessorImpl.
> newInstance(NativeConstructorAccessorImpl.ja
> 
> I have, and like the originally quoted message I am quoting, I zeroed
> in on some code which is in JAXP, which calls the damned
> XMLParserFactory. I didn't write the MochaJournal code either, I
> wonder if the MochaJournal code did something to the SAXParserFactory
> so that it returns wrongly-typed parsers?

This can happen when different class loaders loaded 
javax.xml.parsers.SAXParserFactory and 
org.apache.xerces.jaxp.SAXParserFactoryImpl.
 
> What's strange is that I can call XMLParserFactory.newInstance myself
> and it doesn't throw that exception. It's only when it gets called
> from JAXP that I run into this situation.
> 
> > "com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl" refers
> > specifically to the repackaged version of Xerces in the JDK. The 
regular
> > Apache packages don't have it.
> 
> What version of xerces is included in JDK 1.5?

Given that JDK 1.5 was released before Xerces 2.7.0 (which supports JAXP 
1.3), there isn't a simple mapping between the two. Whatever is in JDK 1.5 
would be considerably different than any Apache Xerces version.
 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-users-help@xerces.apache.org
> 

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org


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


Re: Question about SAX & Xerces

Posted by Alan Ezust <al...@gmail.com>.
On 10/17/05, Elliotte Harold <el...@metalab.unc.edu> wrote:
> Alan Ezust wrote:
>
> > If SAXParserFactory is to be avoided, then why is it used by the JDK 1.5 API?
> > In particular, I am wondering about this
>
> The programmers at Sun make the same mistakes everyone else does.
> Remember, they invented SAXParserFactory in the first place.

Gads, I just realized that the sourcecode for parts of JAXP aren't
even included in the JDK 1.5 src.zip - how annoying. I was trying to
re-engineer the offending classes to use the new SAX API, but I can't
find the sourcecode for
com.sun.beans.ObjectHandler! I wonder why it's so separate from the
rest of the src.zip.

> Why it's throwing a ClassCastException, I don't know. Sounds like a bug.
> Try printing a stack trace. However,

java.lang.ClassCastException:
org.apache.xerces.jaxp.SAXParserFactoryImpl
 at javax.xml.parsers.SAXParserFactory.newInstance(SAXParserFactory.java:107)
 at java.beans.XMLDecoder.readObject(XMLDecoder.java:201)
 at org.homedns.krolain.util.InstallInfo.loadInstallPath(InstallInfo.java:60)
 at org.homedns.krolain.MochaJournal.JLJSettings.LoadSettings(JLJSettings.java:172)
 at livejournal.LoginPane._load(LoginPane.java:117)
 at livejournal.LoginPane.initComponents(LoginPane.java:112)
 at livejournal.LoginPane.<init>(LoginPane.java:50)
 at livejournal.LiveJournalPanel.<init>(LiveJournalPanel.java:25)
 at sun.reflect.NativeConstructorAccessorImpl.newInstance0 (Native Method)
 at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.ja

I have, and like the originally quoted message I am quoting, I zeroed
in on some code which is in JAXP, which calls the damned
XMLParserFactory. I didn't write the MochaJournal code either, I
wonder if the MochaJournal code did something to the SAXParserFactory
so that it returns wrongly-typed parsers?

What's strange is that I can call XMLParserFactory.newInstance myself
and it doesn't throw that exception. It's only when it gets called
from JAXP that I run into this situation.

> "com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl" refers
> specifically to the repackaged version of Xerces in the JDK. The regular
> Apache packages don't have it.

What version of xerces is included in JDK 1.5?

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


Re: Question about SAX & Xerces

Posted by Elliotte Harold <el...@metalab.unc.edu>.
Alan Ezust wrote:

> If SAXParserFactory is to be avoided, then why is it used by the JDK 1.5 API?
> In particular, I am wondering about this

The programmers at Sun make the same mistakes everyone else does. 
Remember, they invented SAXParserFactory in the first place.

Why it's throwing a ClassCastException, I don't know. Sounds like a bug. 
Try printing a stack trace. However, 
"com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl" refers 
specifically to the repackaged version of Xerces in the JDK. The regular 
Apache packages don't have it.

-- 
Elliotte Rusty Harold  elharo@metalab.unc.edu
XML in a Nutshell 3rd Edition Just Published!
http://www.cafeconleche.org/books/xian3/
http://www.amazon.com/exec/obidos/ISBN=0596007647/cafeaulaitA/ref=nosim

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